When the surface of steel is exposed to oxygen, it forms ferric oxide (Fe2O3), which we know as rust. Layers peel off, reducing the structural integrity of the material and exposing more layers to oxygen, creating more rust.
Stainless steel, on the other hand, forms a layer of chromium oxide upon exposure with oxygen. It is a microscopic layer that acts as a force-field and prevents oxygen from reacting with the steel and forming rust.