Soft magnetic materials - like soft iron - can be turned into weak magnets when you place a strong, permanent magnet near them. Steel can also be magnetised (not as easily as iron) but it can stay magnetised longer. You can magnetise a steel rod if you stroke it with a permanent magnet several times in the same direction. You can also place a steel bar in a magnetic field, then heat it to a high temperature and hammer it as it cools. A piece of iron or steel could be magnetised by placing it in a coil of wire with an electric current passing through it, always in the same direction.
Some materials - like iron, cobalt or nickel - have little groups of atoms in them that behave like magnets. These groups of atoms are called magnetic domains. In unmagnetised materials, the magnetic domains are arranged randomly and point in different directions, cancelling each other out. In magnetised materials, the domains are aligned in such a way that they all point in the same direction. The better the alignment is, the stronger the magnet.
The diagram below shows the alignment before and after magnetising a piece of metal:
The reason an unmagnetised nail is attracted to a magnetic piece of iron is that more domains in the nail line up when it is placed near the magnet. When the magnet is removed, most domains return to a random arrangement and the nail becomes demagnetised.
In non-magnetic materials the domains remain in a random arrangement, even when placed in a magnetic field.
Magnetism can also be removed in a number of ways:
Drop or hammer the magnet - this reduces the alignment and the magnetism
Heat the magnet
Stroke one magnet with another in different directions. This works better for demagnetising weaker magnets.