Nodes in wireless sensor networks are generally confined in the energy budget available for their operation, hence energy-aware application design is mandatory to achieve long node lifetimes. Radio transmissions represent an inherent, but energetically costly characteristic of sensor networking. Significant reductions in the overall energy consumption can thus be achieved by reducing both the number of packet transmissions as well as the corresponding packet lengths. Data compression is a viable approach to conserve energy by increasing the information density within packets and thus transmitting shorter packets on the radio. We investigate the compression of packet headers in wireless sensor networks in this paper. Inspired by technologies used in the Internet and characteristics stemming from existing sensor network deployments, we propose a novel scheme for stateful header compression. Our scheme is specifically designed to consider both static and mobile leaf nodes, and can thus be applied in a majority of sensor network deployments. We analyze our scheme in different settings and show that its application leads to reductions of the required transmission energy and thus extended node lifetimes.