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 \times 10^6$ candidates in the $W\rightarrow \mu \nu$ channel and $5.9 \times 10^6$ candidates in the $W\rightarrow e \nu$ 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 \begin{eqnarray} m_W &=& 80370 \pm 7 \, (\textrm{stat.}) \pm 11 \, (\textrm{exp. syst.}) \pm 14 \, (\textrm{mod. syst.}) \, \textrm{MeV} &=& 80370 \pm 19 \, \textrm{MeV}, \end{eqnarray} 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 $m_{W^+}-m_{W^-} = -29 \pm 28$