A magnet can be demagnetized with heat, hammering or an electric current. A metal behaves as a magnet when all its units or domains are aligned in one direction. When this alignment is destroyed and made random, the magnetism is also destroyed.
When heating a magnet, it must be heated for a long duration. Hammering should be done at both poles of the magnet. When an AC current is passed through a solenoid, a magnetic field is created around the object, which destroys the alignment of domains in the object to be demagnetized. The object to be demagnetized can also be rubbed vigorously in both directions with a metallic object, which can cause it to lose its magnetic properties.