Huffman Coding Calculator: Codes, Entropy and Compression
See how Huffman coding compresses a text and compare it with the theoretical limit.
Use the tool
Why this tool exists
The tool counts the characters, builds the Huffman tree by repeatedly merging the two least frequent nodes, assigns codes and lists them with their frequencies. It shows the total encoded size, the average bits per symbol, the Shannon entropy (the lower bound for any symbol-by-symbol code) and the size relative to 8-bit text. The total cost was checked against an independent heap-based implementation and the codes are verified to be prefix-free.
Ties are broken by creation order, so equally optimal trees can give different bit patterns. The size excludes the cost of storing the code table, which matters for short texts.
No data is sent anywhere: the work happens in your browser, so you can use it offline once the page has loaded.
How to use it
- Paste or type some text.
- Read the table of symbols and codes.
- Compare the average length with the entropy.
- Try longer texts to see the ratio approach the entropy.
Frequently asked questions
Is Huffman coding optimal?
Among prefix codes for known symbol frequencies, yes. Arithmetic coding and dictionary methods can do better overall.
Why do different tools give different codes?
Equal frequencies can be merged in different orders, giving different but equally short codes.
What is entropy here?
The average information per symbol from the frequencies, in bits.
Is my data sent anywhere?
No. Everything is processed in your browser, and the page makes no network requests with your input.