A measurement of the mass of the W boson is presented based on proton–proton collision data recorded in 2011 at a centre-of-mass energy of 7 TeV with the ATLAS detector at the LHC, and corresponding to 4.6 fb−1 of integrated luminosity. The selected data sample consists of 7.8×106 candidates in the W → μν channel and 5.9×106 candidates in the W → eν channel. The W-boson mass is obtained from template fits to the reconstructed distributions of the charged lepton transverse momentum and of the W boson transverse mass in the electron and muon decay channels, yielding mW = 80370 ± 7 (stat.) ± 11(exp. syst.) ± 14 (mod. syst.) MeV = 80370 ± 19MeV, where the first uncertainty is statistical, the second corresponds to the experimental systematic uncertainty, and the third to the physics-modelling systematic uncertainty. A measurement of the mass difference between the W+ and W−bosons yields mW+ − mW− = −29 ± 28 MeV.