We use the state-of-the-art semi-analytic galaxy formation model, S, to investigate the physical processes involved in dictating the shape, scatter and evolution of the H -halo mass relation at 0 ≤ z ≤ 2. We compare S with H clustering and spectral stacking of the H -halo mass relation derived from observations finding excellent agreement with the former and a deficiency of H in S at M halo ≈ 10 12−13 M in the latter, but otherwise great agreement below and above that mass threshold. In S , we find that the H mass increases with the halo mass up to a critical mass of ≈ 10 11.8 M ; between ≈ 10 11.8 M and 10 13 M , the scatter in the relation increases by 0.7 dex and the H mass decreases with the halo mass on average (till M halo ∼ 10 12.5 M , after which it starts increasing); at M halo 10 13 M , the H content continues to increase with increasing halo mass, as a result of the increasing H contribution from satellite galaxies. We find that the critical halo mass of ≈ 10 12 M is largely set by feedback from Active Galactic Nuclei (AGN), and the exact shape and scatter of the H -halo mass relation around that mass is extremely sensitive to how AGN feedback is modelled, with other physical processes (e.g. stellar feedback, star formation and gas stripping in satellites) playing a less significant role. We also determine the main secondary parameters responsible for the scatter of the H -halo mass relation, namely the halo spin parameter at M vir < 10 11.8 M , and the fractional contribution from substructure to the total halo mass (M sat h /M vir ) for M vir > 10 13 M . The scatter at 10 11.8 M < M vir < 10 13 M is best described by the black-hole-to-stellar mass ratio of the central galaxy, reflecting the relevance of AGN feedback. We present a numerical model to populate dark matter-only simulations with H at 0 ≤ z ≤ 2 based solely on halo parameters that are measurable in such simulations.