Nail rust because it is made of iron, which is subjected to corrosion.
Corrosion is a chemical process, which consists in the fact that iron is oxidized by oxygen in the air. The result of this process, and rust that looks even remotely resembling metal.
Rust not only nails, but any metal structures exposed to atmospheric oxygen or water: rails, stairs, cars, housing sunken ships. The growing process of oxidation is promoted by oxides of sulfur and nitrogen present in the atmosphere and dissolved in sea water salt.
To protect iron from corrosion, it is necessary to cover the surface of water - and airtight film. For these purposes, oil paint, varnish, chrome and Nickel plating. You can protect iron as if "from the inside". High-alloy steels, for example, for the production of medical instruments, corrosion is not afraid.
Special anti-corrosion coatings are applied to the bottoms of the cars. That's why their owners are not afraid to ride even in the winter with salt, the Russian streets.