To demagnetize a magnet, heat, hammer or jar the magnet, or use an alternating current field. Tools known as demagnetizers also exist that are used to demagnetize screws and steel tools. Magnetism is the result of alignment of magnetic dipoles in material in a direction.
Heating, hammering and jarring a magnet all cause the magnetic dipoles to randomize and lose their original order. The long-range ordering of a magnet is destroyed when it is heated past its Curie point. Hammering or jarring induces vibrations that cause disruptions in dipole order. Alternating currents produce electromagnetic fields that cause the magnetic dipoles to change direction.