Heeding observations, there is plausible evidence for the existence of large-scale magnetic fields in galaxies and in clusters of galaxies. The intriguing problem of the origin of large-scale magnetic fields is examined in the light of our present cosmological understanding. It is argued that primordial magnetic fields are constrained by their effects on the thermodynamic history of the Universe. In particular, if magnetic fields are present prior to the decoupling of radiation from matter, the anisotropies of the Cosmic Microwave Background may be affected.