The heliospheric magnetic field (HMF) is the extension of the coronal magnetic field carried out into the solar system by the solar wind. It is the means by which the Sun interacts with planetary magnetospheres and channels charged particles propagating through the heliosphere. As the HMF remains rooted at the solar photosphere as the Sun rotates, the large-scale HMF traces out an Archimedean spiral. This pattern is distorted by the interaction of fast and slow solar wind streams, as well as the interplanetary manifestations of transient solar eruptions called coronal mass ejections. On the smaller scale, the HMF exhibits an array of waves, discontinuities, and turbulence, which give hints to the solar wind formation process. This review aims to summarise observations and theory of the small- and large-scale structure of the HMF. Solar-cycle and cycle-to-cycle evolution of the HMF is discussed in terms of recent spacecraft observations and pre-spaceage proxies for the HMF in geomagnetic and galactic cosmic ray records.