Corrosion occurs when metals are exposed to moisture, oxygen, and other environmental factors, leading to the breakdown of the material over time.