You may have observed the rail tracks while waiting for a train in the railway station. There are two steel rails which are at a fixed distance called the gauge. In India, there are three gauges – broad gauge (BG), meter gauge (MG), narrow gauge (NG) based on the distance between the rails. BG has 1676 mm (5ft 6 in), MG has 1000 mm (3ft 3 3⁄8 in), and NG has 762 or 610 mm (2 ft). Most of the MG and NG were converted into BG after the year 1991 under project unigauge. However heritage trains like the ones that run in hilly regions to Shimla, Darjeeling, Ooty are not converted.
A rail track is built this way - there is the bare ground, and then a foundation (sand or concrete) is built up to raise the track high enough so it won't get flooded. On top of the foundation is the layer of crushed stone called ballast. The rails are connected to each other either with wood or concrete called sleepers or ties. The rails are bolted to the ties. The track ballast (stones) actually serves many important functions. One of their main functions is to transfer the heavy load above them (on the ties) to the underlying foundation which is made of sand or concrete. The weights of the rails vary from 36 to 73 kilograms per yard (a yard is equivalent 0.9 meters). These stones are subjected to moving loads as heavy as 1,000,000 pounds.
You know that steel is subjected to heat expansion and contraction. There could be very slight movement caused by heat expansion and contraction along the length of the rail. That is why they are just bolted to the ties by clips or anchors and not fixed in place to allow them to move longitudinally during expansion or contraction. The ballast allows for this kind of ground movement and vibration during motion.
Even a slow moving train exerts considerable lateral forces on the tracks. The stone ballast prevents the tracks from moving under the force of a passing train. When there are heavy rains or snow, ballast allows water to drain through them. This also prevents the growth of weeds or thick vegetation that may grow around the track resulting in derailment.