Earth's magnetic field has existed for billions of years, yet the planet is not a permanent magnet: the field would vanish in just 100,000 years if it weren't being regenerated from the core. This generator is the geodynamo.
Earth's core of liquid iron circulates in a spiral flow, powered by thermal convection and twisted by Coriolis forces from its rotation. Huge electric currents arise from this rotation, and these produce the field. The field lines are neat at the Earth's surface, forming the poles we're familiar with. In the liquid core, turbulence pulls the field into a wild knot of spaghetti.
In 1995 Gary Glatzmaier (UCSC) and Paul Roberts (UCLA) created the first self-consistent time-dependent simulation of this process in 3D. Their model works: it predicts the poles and the dynamic interior, as well as the occasional global polarity flip.
Laser etched glass