Energy is a primary constraint in the design and deployment of wireless sensor networks (WSNs), since sensor nodes are typically powered by batteries with a limited capacity. Energy efficiency is generally achieved by reducing radio communication, for instance, limiting transmission/reception of data. Data compression can be a valuable tool in this direction. The limited resources available in a sensor node demand, however, the development of specifically designed compression algorithms. In this paper, we propose a simple lossless entropy compression (LEC) algorithm which can be implemented in a few lines of code, requires very low computational power, compresses data on the fly and uses a very small dictionary whose size is determined by the resolution of the analog-to-digital converter. We have evaluated the effectiveness of LEC by compressing four temperature and relative humidity data sets collected by real WSNs, and solar radiation, seismic and ECG data sets. We have obtained compression ratios up to 70.81% and 62.08% for temperature and relative humidity data sets, respectively, and of the order of 70% for the other data sets. Then, we have shown that LEC outperforms two specifically designed compression algorithms for WSNs. Finally, we have compared LEC with gzip, bzip2, rar, classical Huffman and arithmetic encodings.