Molecule rebounding off of moving surface

Let us take a kinetic theory perspective on why a gas loses energy during an expansion. The gas particles within a piston cylinder are in constant collision with the surface of the piston. If the piston is expanding, the piston head is moving away as the gas particles collide with its surface. During the collision, the particles exert force. A force upon an object moving over a distance performs mechanical work and expends energy. A gas contained within an expanding volume performs work and a gas contained in a contracting volume receives work. The particles, having performed work on the piston head as it expands, rebound with less energy. Likewise, if the piston head moves inward, they particles rebound with more energy. Think about what happens to the energy of a tennis ball if it collides with a racquet moving along with its direction of motion versus one that collides moving directly into the motion of the ball. If no other energy transfers are taking place (no heat flow; i.e. the process is adiabatic) the temperature of the gas will still be changing. In other words, an adiabatic expansion results in a decreased temperature while an adiabatic compression results in temperature increase.