Huffman coding is the classic lossless compression technique that assigns short binary codes to frequent symbols and longer codes to rare ones. Invented by David Huffman as a homework assignment in 1952, it's been the workhorse entropy coder in everything from JPEG and MP3 to early MPEG video and ZIP files. The mathematics is elegant: build a binary tree where common symbols sit close to the root (short codes) and rare symbols sit deep in the tree (long codes), and you provably achieve compression close to the entropy floor for any source where symbol frequencies are known in advance.

The classic example: if the symbol "A" appears 70 % of the time and three other symbols share the remaining 30 %, a fixed 2-bit encoding wastes space. Huffman might encode "A" as just "0", and the others as "10", "110", "111". Now common cases use 1 bit instead of 2, and rare cases pay the price by using 3 bits. The average comes out below 2 bits per symbol — a meaningful saving on long messages.

For a product team, pure Huffman is mostly historical in modern video. JPEG and MPEG-1/2 used it directly; H.264 uses Huffman-style codes inside the simpler cavlc entropy coder, but the better CABAC mode uses arithmetic coding instead. Why the shift: Huffman is limited by its assignment of whole numbers of bits per symbol, whereas arithmetic coding can use fractional bits, getting closer to the entropy floor. The gain is small per symbol but adds up to a few percent of total bitrate. Huffman survives mostly as a foundational concept and inside legacy formats.

Book cover: Video Encoding, Volume 1 of the Fora Soft Video Engineering Handbook

The book · Volume 1 of 7

Video Encoding: A Complete Guide to Video Compression — From Pixels and Color to H.264, HEVC, AV1, Quality Metrics, and AI

Huffman coding gives frequent symbols short codes, and it still sits inside JPEG, MPEG-2 and H.264's CAVLC. Volume 1 covers Huffman coding as part of entropy coding: variable-length codes, why CABAC and arithmetic coding beat it, and where each appears in H.264, HEVC and AV1. Written by Nikolay Sapunov, CEO at Fora Soft.

Read it on Amazon →Kindle & paperback · Fora Soft Video Engineering Handbook

Working on a codec and weighing Huffman coding against arithmetic coding?

Tell us about your codec or format work: we review the entropy coding design and give you a written assessment with measured compression and speed effects. 250+ video products shipped since 2005.

Book a 30-min call →WhatsApp →Email us →