On those rails a multitude of equipment, both powered and rolling stock, rides. When they are not rolling, they need to be maitained, repaired or just stored. This is where the railroad yard comes in.
Most people never think about it, but there are a variety of yards along the tracks.
Some are just rolling stock switching yards, where cars are cut out of one train and placed on another. Some are major terminals for trans-continental mainlines and contain full locomotive and rolling stock shops for major overhauls of the equipment. Some actually depend on gravity to help move the cars around. There is usually at least one yard in most communities of any size. In major metropolian areas multiple yards can be found, especially if more than one railroad serves, or served, a city.