Compression Demos
Classic lossless data compression. Builds an optimal prefix code tree where frequently-used characters get shorter bit codes.
Input Text box — the frequency table, tree, codes, and encoded bits recalculate instantly on every keystroke.hello world or Lorem ipsum to load sample text and see a complete tree without typing.HUFFMAN TREE panel: leaf nodes show a character and its count, while internal nodes (•) show the combined frequency of their subtree.CODES panel, then hit Copy Codes to copy the whole table to your clipboard.ENCODED BIT STRING against the stat grid — Original (bits) versus Encoded (bits) and the resulting Compression Ratio.Clear any time to reset the input and start over.Watch a greedy algorithm give the shortest codes to the most frequent symbols and merge the rarest into a binary tree — exactly as described in algorithms textbooks.
The same core algorithm powers JPEG, PNG, MP3, and ZIP (Deflate). See the encoding step those formats perform under the hood.
Confirm by eye that no code is a prefix of another, which is what lets a decoder split a bit stream back into symbols without delimiters.
Compare Original (bits) (8 bits per character) with Encoded (bits) to see how much a given string actually shrinks.
Short or uniform text yields little or no savings — and can even expand — which is a key reason real codecs combine Huffman with other techniques.
Everything runs locally in your browser. Your text is never uploaded, stored, or sent to a server.
It's a greedy algorithm for building an optimal prefix-free binary code. Symbols that occur more often get shorter bit sequences, minimizing the average number of bits per symbol for a given frequency distribution.
It counts how many times each character appears, then repeatedly merges the two least-frequent nodes into a parent whose frequency is their sum, until one root remains. Left edges are labeled 0 and right edges 1; each character's code is the path from the root to its leaf.
This tool measures the original size as 8 bits per character — the width of an ASCII byte. The Compression Ratio stat shows the encoded size as a percentage of that 8-bit baseline.
Huffman only wins when symbols are unevenly distributed. For very short or uniformly random text, the codes average out to roughly 8 bits or more per character, so the "compressed" size can equal or exceed the original.
A one-symbol tree has no branch to build, so the tool assigns it the trivial code 0. The frequency table and tree show just that single character.
To make invisible characters visible, the tree, frequency table, and code list render space as ␣ (U+2423), tab as \t, and line breaks as \n. The encoding itself still uses the real characters.
No. All counting, tree building, and encoding happen locally in JavaScript. Nothing is uploaded, logged, or sent to a server.