The mechanical work, W, performed upon a gas is given by
where and are points in state space, p is the pressure and V is the volume. The mechanical work done by the gas has the opposite sign (a common source of mistakes).
For reversible changes, where the system evolves through a succession of equilibrium states, one has
and for irreversible changes