Magnetism is a force created by electricity, or more specifically by electrons. In any iron atom, there are 26 electrons. Each electron has a tiny bit of negative charge. The way these electrons behave is impossible for us to imagine, because it’s not like anything we can see. But we can understand it by thinking about it like this:
Imagine an iron atom as being like the teacup ride at the carnival. The electrons all go around the nucleus, like the teacups go around the middle of the ride. At the same time, each electron spins around, like the teacups spin around when you turn the wheel. The electrons, like the teacups, have momentum that makes them spin either clockwise or counter-clockwise.
In most objects, some electrons spin one way and some spin the other way, and they cancel each other out, so most objects are not magnetic. In a chunk of iron, also, some electrons spin one way, and some spin the other way, and most of them cancel each other out. But in iron, there are some extra electrons that can go either way. When you run a magnet over a chunk of iron, those extra electrons all start spinning the way the magnet pulls them, and the chunk of iron becomes a magnet itself.
Many objects in space are magnetic. The Sun, for instance, is very magnetic, because there are places on the Sun where there are a lot of extra electrons or protons. The whole Earth is also highly magnetic, although Mars and Venus are much less so. The Earth’s magnetism pulls negatively charged things like electrons toward the North Pole and positively charged things like protons toward the South Pole. Liquid iron inside the Earth creates (and sometimes changes) the Earth’s magnetism.
Small iron rocks on the surface of the Earth are also sometimes naturally magnetic, with their electrons naturally happening to spin all the same way. We call these natural magnets lodestones.
Until about two hundred years ago, people made magnets by finding a lodestone and rubbing iron on it. The rubbing lined up the electrons of the iron so that all the electrons would pull in the same direction. But today we can use electricity to make magnets.