We present results of calculations of the hadronic vacuum polarisation contribution to the muon anomalous magnetic moment. Specifically, we focus on controlling the infrared regime of the vacuum polarisation function. Our results are corrected for finite-size effects by combining the Gounaris-Sakurai parameterisation of the timelike pion form factor with the Luscher formalism. The impact of quark-disconnected diagrams and the precision of the scale determination is discussed and included in our final result in two-flavour QCD, which carries an overall uncertainty of 6%. We present preliminary results computed on ensembles with $N_f=2+1$ dynamical flavours and discuss how the long-distance contribution can be accurately constrained by a dedicated spectrum calculation in the iso-vector channel.