The formation of magnetic domains is driven by the minimization of the magnetic free energy of the material. When a ferromagnetic material cools below its Curie temperature, spontaneous magnetization occurs, and the material breaks up into domains to reduce its internal energy. The domain structure helps to minimize the magnetostatic energy, exchange energy, and anisotropy energy.