Ancient humans have been aware of the magnetic force ever since at least 600 BC, back before Newton developed this laws of motion, and before we had any grasp of the four fundamental forces  of nature. Despite the fact that we didn't completely understand what magnetism was, we still used compasses back then. Imagine what it must have felt like to use such a device, without knowing the science behind it (though, of course, many of us still use technologies far more sophisticated than a compass, without having a basic idea of how things work).

Some light was shed on this mystery accidentally in 1820 by Hans Christian Ørsted — a Danish physicist born in 1777. While preparing a lecture, he discovered that a compass needle would deflect when brought close to a live electrical wire. People alive at that time already knew the electric force existed, but the connection between electricity and magnetism was revolutionary. Indeed, it took another 45 years until we developed a full explanation of this phenomenon; when James Clerk Maxwell produced the electromagnetic theory of light.

How Magnetism Works:

Maxwell showed that a magnetic field is produced by moving electrical charges. This perfectly explains Ørsted's observation with the needle and live electrical wires. Simply put, this happens because an electric current is simply the movement of electrical charges. Now, we have used this phenomena to create electromagnets,or  long wires wounded to a coil. This way, the magnetic field produced by a single wire is multiplied by the number of turns. Electromagnets have the advantage of being able to be turned on or off anytime we like.

But what about permanent magnets (like bar magnets, refrigerator magnets, etc.)? They obviously don't have electric currents flowing through them. They are a bit more difficult to explain, but, to summarize, the magnetic field from one of these objects is created by three things:

• The first is the orbit of the electron around the nucleus. Although this model that the electron orbits the nucleus has long been proven wrong, it is still a good approximation, and can still be used to explain certain properties of the atom, which is important in the other factors below..
• The second thing that creates a magnetic field is the spin magnetic moment. This is just a technical term that means an  electron, in and of itself, also acts as a magnet. The spin magnetic moment is also a fundamental property of matter, like charge and mass.
• The third factor, which doesn't really affect the magnetic property of the material, is nuclear spin.

With all this in mind, why don't all objects posses magnetic properties? After all, all objects have orbiting electrons, and these electrons all have a spin magnetic moment, right? Well, we have to consider the fact that there are a lot of electrons even in a small amount of material, and the magnetic fields created by these electrons most of the time cancels out.