Magnetostatics defines a class of boundary value problems in which the topology of the domain plays a subtle role. For example, representability of a divergence-free field as the curl of a vector potential comes about because of homological considerations. With this in mind, we study gauge freedom in magnetostatics and its effect on the comparison between magnetic configurations through key quantities such as the magnetic helicity. For this, we apply the Hodge decomposition of k-forms on compact orientable Riemaniann manifolds with smooth boundary, as well as de Rham cohomology, to the representation of magnetic fields through potential one-forms in toroidal volumes. An advantage of the homological approach is the recovery of classical results without explicit coordinates and assumptions about the fields on the exterior of the domain. In particular, a detailed construction of minimal gauges and a formal proof of relative helicity formulas are presented.