How does the metal activity series relate to corrosion?
A metal attached to one lower in the activity series corrodes preferentially and protects less reactive metal.
You can read about the metal activity series at
Corrosion is the electrochemical oxidation of a metal in the presence of water and oxygen. The rusting of iron is a well-known example.
In corrosion, the iron is oxidized to Fe²⁺ ions.
Fe(s) → Fe²⁺(aq) + 2e⁻
The Fe²⁺ ions react with OH⁻ ions to form solid Fe(OH)₂. This further oxidizes and dehydrates to form rust.
If we supply electrons to iron by connecting iron to a more reactive metal such as zinc or magnesium, it will not rust.
This is called sacrificial protection, because the more reactive metal corrodes preferentially, leaving the iron intact.
In the above picture, a strip of zinc sacrificially protects a steel rudder from corrosion.
In the same way, bags of magnesium scrap are attached at intervals to underground pipelines to prevent the iron from corroding.