The addition of rare earth elements changes the electronic structure of metallic materials, especially due to their 4f electrons, which carry a strong magnetic moment. These 4f electrons are well shielded from outside influences, making the magnetism stable and strong. When combined with metals like iron or cobalt, these rare earth elements form alloys with high magnetization and resistance to demagnetization. This improves the magnetic alignment and increases the magnetic anisotropy energy, greatly enhancing the material's magnetic properties.