Coding · Entropy

Huffman coder

A Huffman code built from a text's character frequencies gives frequent characters short codewords and rare ones long codewords, and its average length always lands between the entropy H and H + 1 bits per character, never below H.

Builds on Shape a distribution, Bits as yes/no questions. Taught in Bits & Surprise.

Type or paste text and watch its character distribution, entropy and a live Huffman code: each codeword's length tracks −log₂ p, the average is compared with a fixed-length code, and the encoded bitstream is shown. Presets include a repetitive string and a source whose Huffman average hits the entropy exactly.

The claim above is what this widget demonstrates. Disagree with it?

Where next