When a gas expands or is compressed it exchanges energy with the environment in the form of work. But in almost all real problems the gas is not in contact with a vacuum, but with the atmosphere, which in turn does work. This section carefully distinguishes the work done by the gas on the piston from the work done by the atmosphere on the gas, and assembles them into a complete energy balance that anticipates the first law of thermodynamics.