Changes in ocean heat content (OHC) provide a measure of ocean warming, with impacts on the Earth system. This Review synthesizes estimates of past and future OHC changes using observations and models. The top 2,000 m of the global ocean has significantly warmed since the 1950s, gaining 351 ± 59.8 ZJ (1 ZJ = 1021 J) from 1958 to 2019. The rate of warming increased from <5 to ~10 ZJ yr−1 from the 1960s to the 2010s. Observed area-averaged warming is largest in the Atlantic Ocean and southern oceans at 1.42 ± 0.09 and 1.40 ± 0.09 × 109 J m−2, respectively, for the upper 2,000 m over 1958–2019. These observed patterns of heat gains are dominated by heat redistribution. Observationally constrained projections suggest that historic ocean warming is irreversible this century, with net warming dependent on the emission scenario. By 2100, projected warming in the top 2,000 m is 2–6 times that observed so far, ranging from 1,030 [839–1,228] ZJ for a low-emission scenario to 1,874 [1,637–2,109] ZJ for a high-emission scenario. The Pacific is projected to be the largest heat reservoir owing to its size, but area-averaged warming remains strongest in the Atlantic and southern oceans. Ocean warming has extensive impacts that pose risks to marine ecosystems and society. The projected changes necessitate a continuation and improvement of observations and models, along with better uncertainty estimation.