Many physics analyses using the Compact Muon Solenoid (CMS) detector at the LHC require accurate, high resolution electron and photon energy measurements. Excellent energy resolution is crucial for studies of Higgs boson decays with electromagnetic particles in the final state, as well as searches for very high mass resonances decaying to energetic photons or electrons. The CMS electromagnetic calorimeter (ECAL) is a fundamental instrument for these analyses and its energy resolution is crucial for the Higgs boson mass measurement. Recently the energy response of the calorimeter has been precisely calibrated exploiting the full Run 2 data, aiming at a legacy reprocessing of the data. A dedicated calibration of each detector channel has been performed with physics events exploiting electrons from W and Z boson decays, photons from pi0/eta decays, and from the azimuthally symmetric energy distribution of minimum bias events. The calibration strategies that have been implemented and the excellent performance achieved by the CMS ECAL with the ultimate calibration of Run 2 data, in terms of energy scale stability and energy resolution, are presented.