The spinning of the electrons around the nucleus of an atom creates a tiny magnetic field. The electrons in most objects spin in random directions, and their magnetic forces cancel each other out. Magnets are different because the molecules in magnets are arranged so that their electrons spin in the same direction.