Our planet's magnetic field is believed to be generated deep down in the Earth's core, flowing of liquid metal in the outer core of the planet generates electric currents. And the rotation of Earth on its axis causes these electric currents to form a magnetic field which extends around the planet.