We illustrate the Jarzynski equality on the exactly solvable model of a one-dimensional ideal gas in uniform expansion or compression. The analytical results for the probability density $P(W)$ of the work $W$ performed by the gas are compared with the results of molecular dynamics simulations for a two-dimensional dilute gas of hard spheres.