Steel rusts because of chemical reactions that occur when it comes into contact with water and oxygen. Iron, one component of steel, combines with water and oxygen to produce hydrated iron (III) oxide, which is the chemical that we call rust.
Rust occurs when an item is exposed to wet, oxygen-rich environments; for example, leaving a steel object outside during a rain storm creates an ideal environment for rust to form. This process is accelerated with salt water and with acid rain, as the other chemicals support the reactions that produce rust. As a result, iron and steel boats in the ocean accumulate rust very rapidly. Exposure to water alone does not produce rust; if a steel object is submerged in pure water without access to oxygen, it won't rust.
Stainless steel, as well as other metals like aluminum, are rust resistant because of additional reactions to water and oxygen. Stainless steel contains at least 10 percent chromium, which reacts with water and air to form an extremely thin protective coating outside the metal. This coating blocks water and oxygen from contacting the surface of the metal and interacting with the iron in the stainless steel. Because this film is microscopically thin, it is not visible to the naked eye.