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.6fb-1 of integrated luminosity. The selected data sample consists of 7.8 × 10 6 candidates in the W→ μν channel and 5.9 × 10 6 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 (Formula presented.) 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.