The planet might have a global magnetic field surrounding it. Earth does,
which is why compasses work. So do Mercury, Jupiter, Saturn, Uranus,
and Neptune. Electrical currents
in Earth's core generate its magnetic field. The core consists of iron and
nickel, which are good conductors of electricity. Similarly, Mercury has
an iron core which produces its field. Areas surrounding the cores of Jupiter and Saturn are
filled with liquid metal hydrogen. This strange substance exists only at
the high pressures and temperatures found deep inside massive gas giant
planets.
Flow
of electricity
in the liquid
metal hydrogen produces the strong magnetic fields Jupiter and Saturn. The
magnetic fields of Uranus and Neptune are
generated by current flow in slushy, salty water inside those frozen gas
giants.

The planet might have smaller magnetic fields that surround just part of the
planet. The planet might have had a global magnetic field when it was younger.
Whatever is left of that field can stay "locked into" rocks formed
during earlier times. Mars and Earth's
Moon seem to have local magnetic fields like that. A magnetometer might
also show the location of large deposits of ores such as iron.
Ore
deposits
could even be the remains of an asteroid that struck the planet!

The spacecraft also might detect magnetism caused by
the solar wind or the Sun's
magnetic field. The solar wind is the flow of electrically charged particles
emitted by the Sun. The solar wind carries the Sun's magnetic field outward
through the Solar System. Since the Sun's magnetic field is so strong, the
spacecraft's magnetometer might detect the Sun's
field even when the spacecraft is near a planet. Charged particles from the
solar wind can also become trapped within
a planet's magnetosphere, if the
planet has one. The movement of particles within the magnetosphere
can also produce magnetic fields.

Finally, the magnetic field detected by a spacecraft might be a combination
of several of these effects. For example, the magnetic field
near Earth is a result of the combination of Earth's global field, charged
particles racing around Earth's magnetosphere, and other factors.

You might also be interested in:

The force of magnetism causes material to point along the direction the magnetic force points. As shown in the diagram to the left, the force of magnetism is illustrated by lines, which represent the force....more

The Earth is a good example of a planetary dipole, where the lines of force point in a direction out of the South (magnetic) Pole and into the North (magnetic) Pole. Planets can also show evidence of quadrupoles...more

The Earth has a magnetic field with north and south poles. The Earth's magnetic field reaches 36,000 miles into space. The magnetic field of the Earth is surrounded in a region called the magnetosphere....more

Jupiter's magnetosphere is very special. It is the biggest thing in the entire solar system. Not only is it big enough to hold all of Jupiter's moons, but the sun itself could fit inside. It goes all...more

Saturn's magnetosphere is not as big as Jupiter's, but it is still pretty big. It is big enough to hold all of Saturn's moons. It is probably made the same way as is Jupiter's, which affects its overall...more

The magnetosphere of Uranus is medium sized, but still much bigger than the Earth's. It holds all of Uranus' moons. It is probably made in the middle of the planet, and with ice, rather than with iron...more

Mercury is the only inner planet other than the Earth that has a significant magnetic field (220 nT). This field, along with the planet's high density and small size relative to the Earth, indicates that...more