A heat pump is a heat engine run in reverse. A heat pump causes thermal energy to be moved from a cold reservoir to a hot reservoir. In order for this to occur, work must be done on the system.
An ideal gas can be used as a heat pump. The diagram below illustrates a gas undergoing a cycle of giving out of heat energy to the hot reservoir (1 - 4), expansion (4 – 3), absorption of heat energy (3 - 3) and contraction (4 – 1).
The gas returns to it's initial pressure, volume and temperature. During this process, it has absorbed energy and given out energy. The gas has had work equal to the area under the curve 1 – 2 done on it, and has done an amount of work equal to the area under 3 – 4. The net work done on the gas is the difference between these two, the area of the rectangle above.