A general theory of the magnetic hyperfine structure in diatomic molecules, including states other than 1Σ states, is given. The magnetic hyperfine interaction is derived from the Dirac equation for the electron in the molecular potential field. First-order hyperfine structure formulas are given for the various vector coupling schemes characteristic of molecular states. The 1Σ magnetic hyperfine structures are obtained from second order hyperfine interactions. Applications to the N14O16 and O16O17 microwave spectra are discussed.