Magnets produce magnetic fields due to the motion of electrons within their atoms. In substances like iron, cobalt, and nickel, most electrons spin in the same direction, making the atoms strongly magnetic. There are different types of magnets including permanent magnets made of materials like cobalt, and temporary magnets that are diamagnetic, paramagnetic, or ferromagnetic. Electromagnets are another type of magnet that use electric currents to generate magnetic fields. Magnets can have different shapes that produce distinct magnetic field patterns, such as bar magnets generating field lines between their poles and ring magnets producing closed circular field lines.