When the chromium in stainless steel reacts with oxygen, a thin layer of chromium oxide formed on the alloy surface, the process occurs instantly, the speed should be measured in nanoseconds and film thicknesses in microns. The corrosion resistance of stainless steel results from its ability to form and regenerate the chromium oxide layer in the presence of oxygen. The chrome-containing oxide layer also called a passive film, because the size of chromium atoms are similar to their oxides, they will pack neatly together on the surface and form a stable layer that is a few atoms thick. If the stainless steel is cut or scratched and the film is destroyed, more oxide will form quickly and cover the exposed surface to prevent it from corrosion. Specific additives can assist the alloy to resist certain corrosive chemicals, for example, 316 stainless steel has molybdenum which 304 stainless steel lacks, so the grade 316 alloy has a higher resistance to chlorides than 304.
In the contrast, the iron rusts quickly because the iron atoms are much smaller than its oxide, the oxide layer is loose and easy to fall off.
But stainless steel is not corrosion-resistant under the oxide layer, once the corrosion stats, it will develop rapidly. In addition, the passive film requires oxygen to self-repair, so stainless steels have poor corrosion resistance in low-oxygen and poor circulation environments.