A tamping machine or ballast tamper, informally simply a tamper, is a self-propelled, rail-mounted machine used to pack (or tamp) the track ballast under railway tracks to make the tracks and roadbed more durable and level. Prior to the introduction of mechanical tampers, this task was done by manual labour with the help of beaters. As well as being faster, more accurate, more efficient and less labour-intensive, tamping machines are essential for the use of concrete sleepers since they are too heavy (usually over ) to be lifted by hand.
At its most basic, a tamping machine only packs the ballast. Some modern machines, sometimes known as tamper-liners or tamping and lining machines, also correct the alignment of the rails to make them parallel and level, in order to achieve a more comfortable ride for passengers and freight and to reduce the mechanical strain applied to the rails by passing trains. This is done by finding places where the sleepers have sunk from the weight of the passing trains or frost action, causing the track to sag. The tamper lifts each sleeper and the rails up, and packs ballast underneath. When the sleeper is laid down again, the sagged rails now sit at the proper level. Combining tamping and lining into a single machine saves time and money, as only one machine needs to be run over the track to perform both functions.
Tampers frequently work in concert with ballast regulators, as part of a section crew.
In the early days of railroading, the ballast was maintained by hand, with gandy dancers using shovels and beaters to move, clean, and compact ballast. Rails would be jacked up with large track jacks to allow the crews to do their work. This process took quite a long time and was subject to human error.
Starting in the 1930s, automatic tools for tamping were first developed and used, though they still had to be operated by hand. In the following decades, tamping machines were developed to automate the process, using dedicated machines that travelled on the rails.