The energy calibration and resolution of the electromagnetic calorimeter (ECAL) of the CMS detector have been determined using proton-proton collision data from LHC operation in 2010 and 2011 at a centre-of-mass energy of root s = 7 TeV with integrated luminosities of about 5 fb(-1). Crucial aspects of detector operation, such as the environmental stability, alignment, and synchronozation, are presented. The in-situ calibration procedures are discussed in detail and include the maintenance of the calibration in the challenging radiation environment inside the CMS detector. The energy resolution for electrons from Z-boson decays is better than 2% in the central region of the ECAL barrel (for pseudorapidity vertical bar eta vertical bar < 0.8) and is 2-5% elsewhere. The derived energy resolution for photons from 125GeV Higgs boson decays varies across the barrel from 1.1% to 2.6% and from 2.2% to 5% in the endcaps. The calibration of the absolute energy is determined from Z -> e(+)e(-) decays to a precision of 0.4% in the barrel and 0.8% in the endcaps.