How do magnets work?
The short answer
A magnet is an object wherein most or all of its electrons move in the same direction, creating a magnetic field with north and south ends.
The long answer
To understand how magnets work, let's zoom in all the way to the atomic level. Atoms are the smallest unit of matter, and electrons spin around the nucleus of the atom. The spinning of electrons forms a tiny magnetic field. In most materials, the atoms have electrons that spin in different directions from each other, so their collective magnetic force is canceled out.
But when the electrons of atoms spin in the same direction, a powerful magnetic force is created. Magnetic materials have a flow of magnetic force going out of the north end and entering in south end. This creates what is known as a magnetic field.
When two objects with strong magnetic fields get close to one other, the response will either be attraction or repulsion. If you place a north and a south end of different magnetic objects near each other, they will attract. But north-to-north and south-to-south will cause repulsion.
Not all materials have a strong magnetic field, of course. So when you place a magnetically strong object (e.g. iron) beside a magnetically weaker object (e.g. cloth), there will be no effect.
Now, go forth and admire your refrigerator magnets for their amazing power that they possess!
Sources
Dragonfly Education. (2014). How do Magnets Work? | Engineering Physics. Retrieved October 23, 2022, from https://www.youtube.com/watch?v=MRqQQGO7Xe8&ab_channel=MagicMarks.
Ducksters. (2022). Kids science: Magnetism. Ducksters. Retrieved from https://www.ducksters.com/science/magnetism.php
Magnetism. National Geographic Society. (n.d.). Retrieved October 23, 2022, from https://education.nationalgeographic.org/resource/magnetism
U.S. Energy Information Administration - EIA - independent statistics and analysis. Magnets and electricity - U.S. Energy Information Administration (EIA). (2021, December 13). Retrieved October 23, 2022, from https://www.eia.gov/energyexplained/electricity/magnets-and-electricity.php
Wilson, T. V., &; Pollette, C. (2022, September 20). How Magnets Work. HowStuffWorks Science. Retrieved October 23, 2022, from https://science.howstuffworks.com/magnet.htm