Here's why:
* Convection currents: The outer core is constantly moving due to heat from the inner core and pressure from the mantle. This movement creates electric currents.
* Dynamo effect: These electric currents within the liquid outer core generate a magnetic field, similar to how an electromagnet works.
The Earth's magnetic field extends far beyond the planet's surface, creating a protective shield called the magnetosphere. This shield deflects harmful solar radiation and charged particles from the sun, protecting life on Earth.