Huffman coding · built live in your browser

Compression Tree

Normal text spends 8 bits on every character, even the ones you use constantly. Huffman coding builds a tree that gives common characters short codes and rare ones long codes — then the same sentence fits in far fewer bits. Type anything and watch the tree get built, merge by merge.

Text

try
edit the text — everything below updates 0 / 400
characters
0
distinct
0
original
0 bits
encoded
0 bits
avg / char
0 bits
longest code
0 bits
idle —
original0
huffman0
+0 bits

ready

Huffman tree The tree being built.

Frequency & codes

charfreqsharecodebits

Encoded bits

—
hover any run of bits — or any row in the table — to see which character it is

The tree is read 0 = left, 1 = right; a character's code is the path from the root down to its box. Most-used characters end up nearest the root, so they get the shortest codes. Try One letter for the extreme case, or All different to see what happens when nothing repeats.