Corrosion is caused when an area of metal has a positive charge and another has a negative charge. Water acts as an electrolyte, allowing current to flow between these areas. During this process the metal absorbs oxygen from the water and forms iron oxide (rust). Salt water conducts electricity better than fresh water so in areas that use salt on the roads, this process is greatly accelerated.
The objective of applying a protective coat of paint is to insulate the metal from water. To ensure that no rust is present before we coat the metal, we clean the metal with an acid (phosphoric based, which leaves a thin film of iron phosphate or zinc phosphate that prevents flash rusting), and then apply a zinc phosphate coating which neutralizes the acid, and promotes primer adhesion. Zinc (galvanized and zinc rich primers) competes with the iron for oxygen, and becomes the sacrificial metal which corrodes, leaving the iron undamaged.