Rusting is the reaction of iron with oxygen, but water is also an important part of the process. When acidic substances, including water, come in contact with metals such as iron and steel, rust begins to form. Rust is the result of corroding steel after the iron particles have been exposed to oxygen and moisture, such as humidity, vapor, or immersion. The molecules of iron on the surface of the nail exchange atoms with the oxygen in the air and produce a new substance, the reddish-brown ferrous oxide, also known as rust.
In summary, the presence of water is necessary for rusting to occur, as it acts as a catalyst in the reaction of oxidation of iron to get rusted. Oxygen is also required for rusting to form, as it bonds with iron atoms to form iron oxides.