This paper presents the electron and photon energy calibration achieved with the ATLAS detector using about 25 fb(-1) of LHC proton-proton collision data taken at centre-of-mass energies of root s = 7 and 8 TeV. The reconstruction of electron and photon energies is optimised using multivariate algorithms. The response of the calorimeter layers is equalised in data and simulation, and the longitudinal profile of the electromagnetic showers is exploited to estimate the passive material in front of the calorimeter and reoptimise the detector simulation. After all corrections, the Z resonance is used to set the absolute energy scale. For electrons from Z decays, the achieved calibration is typically accurate to 0.05\% in most of the detector acceptance, rising to 0.2\% in regions with large amounts of passive material. The remaining inaccuracy is less than 0.2-1\% for electrons with a transverse energy of 10 GeV, and is on average 0.3\% for photons. The detector resolution is determined with a relative inaccuracy of less than 10\% for electrons and photons up to 60 GeV transverse energy, rising to 40\% for transverse energies above 500 GeV.