Skip to content
100% local

Huffman coding

Compress text with a Huffman tree, or decode a Huffman-coded container back to the original.

Input
Output

Huffman coding

Huffman coding is the classic compression algorithm behind formats like DEFLATE and JPEG: it counts how often each byte appears, builds a tree that gives common bytes short codes and rare bytes long codes, then rewrites the data as that string of bits. This tool builds the tree for whatever you paste in, encodes it, and decodes its own output back to the original — useful for seeing how the algorithm behaves on real text, or checking how much a message would shrink.

Set Direction to Encode or Decode. Data format is the plain side — Text reads UTF-8 characters, Hex bytes reads pairs like "48 65 6c", and Decimal bytes reads numbers from 0 to 255. Encoded format is the compressed side: Binary shows the raw 0s and 1s, Hex packs them into byte pairs, and Base64 packs them shorter still. Wrap output at N breaks a long container into readable lines without affecting decoding, since line breaks are stripped before a container is read back. Pad binary output to a full byte only matters for the Binary format — Hex and Base64 always pack to full bytes anyway.

The container carries a small header — a marker, the original length and the frequency table — so the tree rebuilds exactly on decode without shipping the tree itself. Paste a container back in with Direction set to Decode and matching formats to get the exact original bytes back, including diacritics, emoji and line endings. Very short or near-random inputs may not shrink at all, since Huffman coding only saves space when some bytes are genuinely more common than others.

Everything runs locally in your browser — nothing you paste is uploaded anywhere. Copy the result, download it as a .txt file, or send the output back into the input to decode what you just encoded.

FAQ

Why does the encoded output look so much longer than my input for short text?
A Huffman container includes a small header with the frequency table needed to decode it. For very short inputs that header outweighs the savings; the benefit grows with longer, more repetitive text.
Can I decode a container I encoded with different options?
No. Set Data format and Encoded format to match what was used to create the container, or decoding will fail with an error rather than return garbled data.
What does 'Pad binary output to a full byte' change?
It only affects the Binary encoded format, rounding the bit string up to a multiple of eight with trailing zeros. Hex and Base64 always pad internally, since they can only represent whole bytes.
Does this produce a real compressed file I can use elsewhere?
No. It builds a standalone, self-describing container specific to this tool so you can see the algorithm work and round-trip your own text — it isn't compatible with gzip, ZIP or other Huffman-based formats.
Is my text uploaded anywhere?
No. Building the Huffman tree and encoding or decoding your text happens entirely in your browser — nothing is sent to a server.