Iron combines with moisture and oxygen in the air very easily. It forms a new material called an oxide. But that oxide takes up more space than the iron, so the surface swells and pushes clear of the surface. We see that as rusty flakes. Because the flakes push clear of the surface, more moisture and oxygen can get at the iron underneath and begin to make that go rusty, too.
Iron and steel only go rusty when they are in damp air. To stop them going rusty the moisture in particular must be kept away from the iron. This is most easily done by giving it a coating. That is why iron (and many ordinary steel) objects are often painted. However, the paint cracks in time, so iron objects that are out in the weather (for example railings and gates) need to be painted regularly. Another, more expensive, way to protect iron and steel is to coat it in resin and plastic. This is what is done to automobiles, and why they no longer rust easily.