Every time you save a ZIP file, stream a video, or send a message, a small algorithm decides how many bits each symbol deserves. The goal is always the same: use as few bits as possible without losing any information.
Claude Shannon proved in 1948 that there is a hard floor on how short any lossless code can be. For a symbol with probability p, the ideal code length is − bits — exactly. A coin-flip symbol (p = 0.5) deserves exactly 1 bit. A rare symbol (p = 0.0625) deserves 4 bits. The average across all symbols is the Shannon entropy of the source, and no lossless code can beat it.
Three generations of algorithms have chased that floor:
- Huffman coding (1952) — assigns whole numbers of bits per symbol. Fast and simple, but whole-bit rounding wastes space whenever the ideal length is not an integer.
- Arithmetic coding (1970s–80s) — encodes an entire message as a single fraction, achieving the entropy limit to arbitrary precision. Nearly optimal, but the multiplications and divisions make it slow.
- ANS — Asymmetric Numeral Systems (Jarek Duda, ~2009) — encodes state in a single integer using table lookups, matching arithmetic coding's precision at speeds that rival Huffman coding.
Today ANS powers zstd, lz4, LZFSE, and every frame of video compressed with HEVC or AV1. Understanding why it replaced arithmetic coding means understanding what "reaching the entropy limit" actually costs — and how a clever bijection between integers and bit sequences makes it almost free.
Comments
Loading comments...