What causes Earth’s magnetic field?

Earth magnetic field

Earth’s magnetosphere – the area influenced by its magnetic field – is the result of moving electric fields in the liquid molten iron core. Compared to the surface, the magnetic field at the core is around 50 times stronger.
It’s believed that Earth has had a magnetic field for pretty much all its 4.5-billion-year lifetime. However, when our planet first formed, it’s likely that the entire core was liquid; at the moment, only the outer core is liquid, with the inner core being solid due to the intense pressure. This would mean that Earth’s early magnetism would have been considerably stronger than it is now. Exactly how much more intense we can’t be sure, but it’s believed this strong magnetic field was what helped Earth retain an atmosphere early in its development, in the opposite way that Mars has lost its atmosphere as its magnetic field has dissipated.