The magnetic field is generated by electric currents due to the motion of convection currents of a mixture of molten iron and nickel in the Earth's outer core: these convection currents are caused by heat escaping from the core, a natural process called a geodynamo.
Heat is also being transferred from the solid inner core to the liquid outer core, and this leads to convection of the liquid iron of the outer core. Because iron is a metal and conducts electricity (even when molten), its motion generates a magnetic field.
Earth’s magnetic field is generated within the outer core by the convective movement of liquid iron. the magnetic field is not stable over geological time. For reasons that are not completely understood, the magnetic field decays periodically and then becomes re-established. When it does re-establish, it may be oriented the way it was before the decay, or it may be oriented with the reversed polarity. Over the past 250 Ma, there have a few hundred magnetic field reversals, and their timing has been anything but regular.
The shortest ones that geologists have been able to define lasted only a few thousand years, and the longest one was more than 30 million years, during the Cretaceous. Earth’s magnetic field is defined by the North and South Poles that align generally with the axis of rotation. The lines of magnetic force flow into Earth in the northern hemisphere and out of Earth in the southern hemisphere.
The outer core of the Earth is a liquid layer about 2,261 km thick composed of iron and nickel which lies above the Earth's solid inner core and below its mantle. Its outer boundary lies approximately 2,890 km (1,800 mi) beneath the Earth's surface. The transition between the inner core and outer core is located approximately 5,150 km beneath the Earth's surface.
The temperature of the outer core ranges from 4400 °C (7952 °F) in the outer regions to 6100 °C (11012 °F)near the inner core. Eddy currents in the nickel-iron fluid of the outer core are believed to influence the Earth's magnetic field. The outer core is not under enough pressure to be solid, so it is liquid even though it has a composition similar to that of the inner core. Sulfur and oxygen could also be present in the outer core.
Without the outer core, life on Earth would be very different. Scientists believe that the convection of liquid metals in the outer core creates the Earth's magnetic field. This magnetic field extends outward from the Earth for several thousand kilometers, and creates a protective bubble around the Earth that deflects the Sun's solar wind. Without this field, the solar wind would have blasted away our atmosphere, and Earth would be lifeless like Mars.
At the North and South Poles, the force is vertical. Anywhere on the equator the force is horizontal, and everywhere in between, the magnetic force is at some intermediate angle to the surface. Because of the shape of the field lines, the magnetic force trends at different angles to the surface in different locations