The Earth acts as a magnet because of electric currents generated through the movement of iron in the Earth's molten core. This motion creates a very weak magnetic force that expands from Earth reaching tens of thousands of miles into space.
The electric forces emanating from the Earth's core result in electromagnetic forces with magnetic poles near the North and South Poles. These magnetic forces are why compasses point toward north; the magnetic component of the compass is attracted to the forces at the North Pole. The magnetic North Pole is slightly offset from the geographic North Pole. The magnetic axis of the Earth tilts slightly away from the axis of rotation, and this tilt varies from year to year. On average, the magnetic axis is about 11.3 degrees offset from the axis of rotation.
The magnetic field of the Earth keeps the planet safe from hazardous radiation in space. The sun constantly releases charged, radioactive particles. These particles are known as solar wind. The magnetic field keeps these radioactive particles from raining down on the surface of the Earth. As the particles approach Earth, the magnetic forces deflect them around the atmosphere. Without these forces, the particles would destroy the Earth's atmosphere and expose the plants and animals to deadly amounts of radiation. Scientists believe solar winds stripped the atmosphere from Mars because Mars does not produce protective magnetic fields.