Compress and Decompress Text
Compress text with gzip, zlib deflate, Brotli or LZ4 and get Base64 output with real byte counts, or paste Base64 back in to decompress it.
The interactive tool loads here when JavaScript runs.
About this toolWhat is the Compression Tool?
This tool compresses text with real codecs: gzip and zlib deflate via pako, Brotli via the brotli-wasm build of Google's encoder, and LZ4 via lz4js. Compressed output is binary, so it is shown as Base64, and the badge reports the size of the compressed bytes against the UTF-8 size of your input, for example 1050 → 50 bytes, 95.2% smaller.
Decompress reverses it: choose the same format, paste the Base64 and the original text comes back. The same screen also offers Base64, URL and hex encoding, which are not compression at all. They always make data larger, and the badge says so.
Everything runs in your browser. Brotli is a WebAssembly module loaded the first time you use it. Input is text, so the tool is for strings, payloads and config, not for compressing binary files.
- Real gzip, zlib, Brotli and LZ4 codecs, no simulations
- Honest size badge in bytes, including when output grows
- Decompression of Base64 input back to UTF-8 text
- Base64, URL and hex encoding on the same screen
- Runs locally; Brotli loads as WebAssembly on first use
Updated
How to use the Compression Tool
- Pick Compress or Decompress under Operation.
- Pick a Format: Gzip, Deflate (zlib), LZ4 or Brotli for compression, or Base64, URL Encoding or Hex Encoding.
- Paste text into Input Text. For decompression, paste the Base64 this tool produced (or hex or URL text for those formats).
- Click Compress or Decompress. The badge shows input and output sizes in bytes and the percentage change.
- Use Copy Result or Download to keep the output.
Worked examples
Repetitive JSON compresses well
Input
{"id":1,"name":"Ada"} repeated 50 times (1050 bytes), GzipOutput
1050 → 50 bytes, 95.2% smaller
Fifty copies of the same object are almost pure repetition. Deflate (zlib) gets 38 bytes because its wrapper is 12 bytes smaller than gzip's.
Short strings get bigger
Input
hello world, Gzip
Output
H4sIAAAAAAAAA8tIzcnJVyjPL8pJAQCFEUoNCwAAAA== 11 → 31 bytes, 181.8% larger
The 18 bytes of gzip header and trailer dwarf an 11-byte input. Base64 of the same text is 16 bytes, 45.5% larger.
Background and insight
gzip (RFC 1952) and zlib (RFC 1950) are two wrappers around the same DEFLATE stream (RFC 1951) from 1996, which combines LZ77 back-references with Huffman coding. gzip adds a 10-byte header and an 8-byte CRC-32 and length trailer; zlib adds 2 bytes in front and a 4-byte Adler-32 checksum. HTTP's Content-Encoding: deflate means the zlib form, which is why this tool labels it Deflate (zlib).
Brotli (RFC 7932, 2016) was designed at Google for the web. Besides a larger window and better context modelling, it ships a built-in dictionary of common words and HTML, CSS and JavaScript fragments, which is why it beats gzip most clearly on small web text. LZ4, written by Yann Collet in 2011, goes the other way: very fast compression and decompression in exchange for lower ratios, which suits databases, caches and log pipelines.
Every format has fixed overhead, so tiny inputs grow. "hello" is 5 bytes; gzip turns it into 25, and LZ4's frame format into 20. Compression only pays off once the input is long enough to contain repeats. For speed and size side by side on your own data, use the Compression Comparison tool.
Common use cases
Reading a compressed payload
Decode a Base64 gzip blob from a log line, a message queue or a cookie to see what is inside.
Choosing a codec
Check how much a real API response shrinks with gzip versus Brotli before changing server settings.
Packing data into a URL or env var
Compress a long JSON config, then use the Base64 output where only short text fits.
Testing a decompressor
Produce known-good gzip, zlib, Brotli and LZ4 samples for unit tests.
Tips and limitations
- Output uses standard Base64. If you need URL-safe Base64, replace + with - and / with _ afterwards.
- Gzip and Deflate (zlib) contain the same compressed data, so their sizes differ by exactly 12 bytes.
- LZ4 output is the LZ4 frame format (magic 04 22 4D 18), which the lz4 command-line tool reads, not raw LZ4 blocks.
- Brotli runs at quality 11, the setting used for pre-compressed static assets. Servers compressing on the fly usually use 4 to 6.
- Snappy is not offered because no Snappy codec is bundled. Parquet and Kafka files that use it need a native tool.
Sources and further reading
- RFC 1950: ZLIB Compressed Data Format Specification version 3.3, Internet Engineering Task Force. The 2-byte header and Adler-32 trailer
- RFC 1951: DEFLATE Compressed Data Format Specification version 1.3, Internet Engineering Task Force. LZ77 plus Huffman coding
- RFC 1952: GZIP file format specification version 4.3, Internet Engineering Task Force. The 10-byte header and CRC-32 and length trailer
- RFC 7932: Brotli Compressed Data Format, Internet Engineering Task Force. Brotli, including its built-in static dictionary
- LZ4 Frame Format Description, LZ4 project. The frame format behind LZ4's fixed overhead
Frequently asked questions
How do I decompress a gzip Base64 string online?
Set Operation to Decompress and Format to Gzip, paste the Base64 string and click Decompress. A gzip Base64 string usually starts with H4sI, which is the encoding of the gzip magic bytes 1F 8B 08. The result must be UTF-8 text.
What is the difference between gzip and deflate?
They hold the same DEFLATE-compressed data with different wrappers. gzip adds a 10-byte header and an 8-byte CRC-32 trailer; zlib, which HTTP calls deflate, adds a 2-byte header and a 4-byte Adler-32. Use gzip for files and HTTP, zlib inside formats such as PNG.
Why is my compressed output bigger than the input?
Short inputs do not contain enough repetition to pay for the format overhead. gzip alone adds 18 bytes, so "hello" grows from 5 to 25 bytes. The Base64 display adds another third on top, which is why sizes are measured on the raw compressed bytes.
Is Brotli better than gzip?
For web text it is usually smaller at similar decompression speed, which is why browsers and CDNs support it. At quality 11 it compresses much more slowly than gzip, so it is best for assets compressed once at build time. Measure your own data in the Compression Comparison tool.
Why is Base64 listed if it does not compress?
It is here for convenience because compressed data is binary and usually travels as Base64. Base64 turns every 3 bytes into 4 characters, so it always adds about 33 percent. URL and hex encoding grow data even more.
Can I compress a file instead of text?
Not with this tool. It reads text from the input box and works on its UTF-8 bytes. For files, use gzip, brotli or lz4 on the command line, or the Image Compressor for pictures.
Is there an in-depth guide to the Compression Tool?
Yes. “Gzip vs Brotli vs LZ4: Choosing a Compression Algorithm” covers the background, how it works, common pitfalls and worked examples. Read the full guide.
Related Tools You May Like
Free, in-browser tools that pair well with this one.