How JPEG XL Recompresses JPEG Files Losslessly
JPEG XL offers a unique feature that allows existing legacy JPEG files to be reduced in file size by roughly 16% to 22% without any loss in visual quality or generational degradation. Rather than decoding the image into raw pixels and re-encoding it, JPEG XL operates directly on the underlying mathematical components of the original JPEG file. By unpacking the legacy entropy coding and re-encoding the original frequency data with modern, highly efficient compression algorithms, JPEG XL achieves significant size reduction while maintaining the ability to reconstruct the original JPEG file bit-for-bit.
Bypassing Pixel Decoding
Standard image conversion typically decodes a file into raw RGB or YUV pixels and then compresses those pixels using a new format. This process inevitably introduces generational loss because the original compression artifacts are baked into the raw pixels and compressed a second time.
JPEG XL avoids this entirely. It does not touch the decoded pixels. Instead, it reads the legacy JPEG bitstream and stops after decoding the entropy layer, leaving the core mathematical representation of the image intact.
Extracting and Preserving DCT Coefficients
Legacy JPEG images store visual information in the frequency domain using the Discrete Cosine Transform (DCT) across 8x8 pixel blocks. During the original creation of a JPEG, these 8x8 DCT blocks are quantized (which is where the initial lossy compression occurs) and then encoded using Huffman coding.
When JPEG XL losslessly recompresses a JPEG, it reverses the Huffman coding to extract the exact quantized DCT coefficients, along with the original quantization tables, color space markers, and embedded metadata such as EXIF and ICC profiles. Because the quantized coefficients themselves are preserved rather than recalculated, no new compression artifacts can be introduced.
Modern Entropy Coding with ANS
Legacy JPEG relies on Huffman coding, an entropy coding technique from the 1950s that is computationally lightweight but inefficient by modern standards. JPEG XL replaces this system with Asymmetric Numeral Systems (ANS), specifically a variant adapted for image data.
ANS allows fractional bits of information to be stored per symbol, whereas Huffman coding must round to whole bits. Combined with sophisticated context modeling—which predicts upcoming frequency values based on surrounding 8x8 blocks—JPEG XL packs the identical DCT coefficients into a substantially smaller footprint.
Lossless Invertibility
The recompression process is entirely reversible. JPEG XL packages the original quantization matrices, layout headers, and non-image metadata alongside the ANS-compressed DCT coefficients.
Because all the fundamental building blocks of the original legacy file are retained without modification, a system can decompress the JPEG XL container and restore the exact, byte-identical original JPEG file on demand. This allows servers and storage systems to shrink existing JPEG libraries immediately without breaking backward compatibility for older clients that do not support modern formats.