This is a drawing of Earth with its magnetic field.
Click on image for full size
Planets have magnetic fields that start deep inside themselves.
Not every planet has a magnetic field. Mercury, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune have magnetic fields. Venus is a special case of a rocky planet with no magnetic field.