When you put trash into the trash container, close the door, and press or turn the Start button, the motor starts. It rotates a set of reduction gears or a belt-and-pulley system that slowly lowers the ram.
The ram exerts tremendous pressure on the trash, which flattens it. When the ram pressure reaches its setpoint, the motor reverses and raises the ram back up to the top of the compactor.