all the molecules of a magnetic substance is an independent
magnet. in an unmagnetized magnetic substance, the molecular
magnets are randomly oriented. they form dosed chains so they
neutralize the effect of each other. these chains are called
domains and each molecular magnet is called dipole.
when a substance is magnetized, the molecular magnets are
arranged in one direction by breaking the domains. the end where
all the north poles of the dipoles are present becomes the north
pole of the magnet. the other end where south pole of the dipoles
are present becomes the south pole of the magnet.
when the magnet is strongly heated or hammered the kinetic
energy of the molecules increases and therefore the molecules
alignment gets disrupted and the molecules go back to the closed
chain arrangement to form domains and thus the magnet gets
demagnetized :) thank you.