Modern imaging technology permits obtaining images at varying depths along the thickness, or the Z-axis of the sample being imaged. A stack of multiple such images is called a Z-stack image. The focus capability offered by Z-stack images is critical for many digital pathology applications. A single Z-stack image may result in several hundred gigabytes of data, and needs to be compressed for archival and distribution purposes. Currently, the existing methods for compression of Z-stack images such as JPEG and JPEG 2000 compress each focal plane independently, and do not take advantage of the Z-signal redundancy. It is possible to achieve additional compression efficiency over the existing methods, by exploiting the high Z-signal correlation during image compression. In this paper, we propose a novel algorithm for compression of Z-stack images, which we term as ZPEG. ZPEG extends the popular discrete-cosine transform (DCT) based image encoder to compress Z-stack images. This is achieved by decorrelating the neighboring layers of the Z-stack image using differential pulse-code modulation (DPCM). PSNR measurements, as well as subjective evaluations by experts indicate that ZPEG can encode Z-stack images at a higher quality as compared to JPEG, JPEG 2000 and JP3D at compression ratios below 501.