Nails rust in water or in moist air because oxygen in the water or air combines with the iron to form various iron oxides. The commonest is red oxide. If salt is present there is also an electrical effect (electro chemical reaction) which increases the rate of corrosion. So iron 'rusts' more rapidly in sea water than fresh water.