How do you demagnetize a magnet?
A permanent magnet was magnetized when it was first made out of metal. It did have microscopic regions of magnetic order—magnetic domains—but those regions all pointed in random directions and the magnet didn’t have any overall magnetic poles. To give it poles, it had to be magnetized. It was placed in a very strong magnetic field so that its domains grew or shrank until most of them were aligned with the magnetic field. The magnet acquired overall magnetic poles for the first time. When the field was removed, the domains remained as they were and the magnet permanently retained its new magnetic poles.
If this same magnet were reversed and then placed in that strong magnetic field again, it would become remagnetized in the opposite direction from before—its domains would grow or shrink until most of them were aligned with the magnetic field again. The magnet’s north poles would become south poles and vice versa. Finally, if the magnet were wiggled back and forth in that strong magnetic field and gradually removed from the field, its domains would grow or shrink almost randomly. The magnet’s magnetic domains would become randomized and it would end up with no overall north or south magnetic pole at all. It would be demagnetized.