Acid rain is formed when sulfur dioxide and nitrogen oxides react with water and oxygen in the atmosphere to produce sulfuric and nitric acids.