Nails rust in water because water allows the iron to react with any oxygen present, which forms iron oxide, known as rust. In order to cause rust quickly, there must be some impurities in the water, particularly salts, since these speed up the transfer of electrons from iron to oxygen.
Salt water greatly accelerates rusting, as does acidic water, such as acid rain. This is because as the water and oxygen react with the iron, hydroxide ions are formed. Acids react with the hydroxide ions, allowing the reaction to proceed more easily. The acids also react with the metals themselves, allowing oxygen and water to penetrate deeper into the metal. One form of iron oxide actually adheres to the metal surface, protecting underlying metal from further corrosion. However, when carbon dioxide or sulfur dioxide are present in the water, a different kind of iron oxide is formed. This flaky rust peels away from the underlying metal, leaving it exposed to oxidation.
Rust causes a huge amount of damage to man-made structures, but scientists have discovered many ways to prevent it. Coating iron in paint or other metals keeps water and oxygen from reaching the surface. Applying a particular electric charge to the metal also prevents the oxidation reaction from occurring.