Magnetism is one of the main forces of nature, like the force of gravity. Like gravity, which causes objects to be attracted to each other, magnetis,m causes magnetized objects to be attracted to each other.
In most cases, planetary magnetic fields are made by currents of molten material which move around deep within a planet.
An example of the force of magnetism at work is the magnet from your kitchen which sticks to the refrigerator door.
On Earth, a simple compass can always be used to detect the presence of the magnetic field of the earth around you, as well as any other nearby magnetic field.