Why Gzip and Brotli Do Not Compress JPEGs

Applying compression algorithms like Gzip or Brotli to JPEG images yields virtually no reduction in file size and can even increase the overall payload. This occurs because the JPEG format already incorporates aggressive lossy and lossless compression techniques, leaving the data with high information entropy and zero structural redundancy for general-purpose algorithms to exploit.

JPEGs Are Already Fully Compressed

A JPEG image is not raw bitmap data. When an image is saved as a JPEG, it undergoes a multi-step compression pipeline:

  1. Color Space Conversion and Downsampling: Chrominance data is reduced because human eyes are less sensitive to color shifts than brightness.
  2. Discrete Cosine Transform (DCT): Spatial pixel blocks are converted into frequency components.
  3. Quantization: High-frequency details are discarded (the lossy step).
  4. Entropy Encoding: The remaining data is packed using Huffman coding or arithmetic coding (the lossless step).

By the time the JPEG file is assembled, virtually all repeating sequences and statistical redundancies have already been extracted and eliminated.

The Mathematics of Entropy

Both Gzip (which relies on DEFLATE) and Brotli function by finding repeated patterns of bytes (using the LZ77 algorithm) and replacing frequently occurring symbols with shorter codes (using Huffman coding or Asymmetric Numeral Systems).

These algorithms rely entirely on low data entropy—meaning the presence of predictable, repeated patterns, such as those found in HTML, CSS, JavaScript, and uncompressed text.

A finalized JPEG stream resembles pseudorandom noise to compression tools. Because the bytes in the JPEG bitstream are already distributed with near-maximum entropy, Gzip and Brotli cannot find repeated byte sequences to tokenize, nor can they build a more efficient frequency tree than the one already built into the JPEG.

The Negative Impact: File Expansion and CPU Waste

When an algorithm like Gzip or Brotli attempts to process an incompressible file, two negative outcomes occur:

Best Practices for Web Delivery

Web servers (such as Nginx, Apache, or Caddy) and Content Delivery Networks (CDNs) should be configured to exclude image MIME types from Gzip and Brotli encoding rules. Compression should be reserved for text-based assets (text/html, application/javascript, image/svg+xml, etc.).

To reduce JPEG file sizes, optimization must happen at the image level using dedicated image compressors (such as MozJPEG) or by converting the images to modern web formats like WebP or AVIF.