Consider an ideal gas at a pressure P enclosed in a cylinder of cross
sectional area A.
The gas is then compressed by pushing the piston in a distance dx, the
volume of the gas decreasing by dV. (We assume that the change in volume is small so that
the pressure remains almost constant with a value P).
Work done on the gas
during this compression = dW
Force on piston = PA
So the work done during
compression = dW = PAdx = PdV