Skip to content

Entropy coding

The final, lossless stage of image compression — squeezing out the last bits by representing common values more compactly.

On this page

Definition

Entropy coding is a lossless compression step that represents frequently occurring values with short codes and rare values with long ones. It's the last stage of most image codecs: PNG's DEFLATE, JPEG's Huffman tables, and the arithmetic/ANS coding in AV1 and WebP. Because it's lossless, re-encoding it more aggressively can only help.

In practice

This is what a PNG optimizer like OxiPNG attacks: it re-runs entropy coding with stronger settings and better filters to produce a mathematically identical but smaller file. It's why \"lossless optimization\" is real and why two PNGs of the same pixels can have different file sizes.

This is lossless compression in action: a mathematically identical file, produced by better entropy coding and filters.

The idea, explained plainly

Entropy coding is easier to grasp through a postal analogy than through information theory.

Suppose you must send thousands of letters and 90% of them go to one address. Writing the full address on every envelope wastes space. Instead, agree in advance that a short mark means that address, and reserve longer marks for the rare destinations. Total characters sent drops sharply, and nothing is lost — the recipient still knows exactly where each letter goes.

Entropy coding does this with numbers. It builds a table mapping each value to a code whose length depends on how often that value appears, then writes only the codes. Frequent values get short codes; rare ones get long codes. The decoder reads the same table and reconstructs the original exactly.

Why it matters to you

This stage is why "lossless optimisation" is a real, honest claim rather than a contradiction — and why it has a hard ceiling.

Because entropy coding only changes representation, a tool can redo it more thoroughly than your original encoder did and produce a smaller file with pixel-identical output. Encoders are frequently conservative here: they pick a safe default table and move on, leaving measurable slack. A determined optimiser will search for a better table and find it.

The ceiling is set by the data itself. Entropy coding cannot invent compression where there is no statistical structure — random noise has none, and no amount of cleverness will shrink it. This is exactly why a photographic PNG barely improves while a screenshot improves a lot, and why running a second optimiser over an already-optimised file achieves nothing.

Compress your images now — free and private

Process up to 200 images locally. Choose a format, compare the results and download a ZIP.

Open the compressor
100% private No signup

Frequently asked questions

It's the final lossless stage of most image codecs, where frequently occurring values are encoded with short codes and rare values with long ones. PNG uses DEFLATE, JPEG uses Huffman tables, and AV1/WebP use arithmetic or ANS coding.

Yes, always. Entropy coding only changes how data is represented, never the data itself. That's why PNG optimizers like OxiPNG can shrink files with zero quality loss — they only redo this stage more efficiently.

Because the entropy-coding stage is not fully determined. Encoders choose how hard to search for optimal codes, so a conservative encoder leaves slack that a thorough optimiser can recover. Two PNGs with identical pixels can differ in size purely because they were encoded with different effort.

No. Entropy coding cannot create structure that is not there. Image data with genuine statistical redundancy shrinks well; random noise does not compress at all. Once a file has been optimised, further passes yield nothing because there is no remaining redundancy to encode away.