There are several ways to prevent iron and steel rusting. Some work because they stop oxygen or water reaching the surface of the metal:
Iron and steel objects may also be covered with a layer of metal. Food cans are plated with a thin layer of tin.
Galvanising is a method of rust prevention. The iron or steel object is coated in a thin layer of zinc. This stops oxygen and water reaching the metal underneath – but the zinc also acts as a sacrificial metal. Zinc is more reactive than iron, so it oxidises rather than the iron object.
Sacrificial protection - Higher tier
A reactivity series lists metals in order of how reactive they are.
Magnesium and zinc are often used as sacrificial metals. They are more reactive than iron and lose their electrons in preference to iron. This prevents iron from losing its electrons and becoming oxidised.