Gzip text compressor

Compress and decompress text or bytes with gzip, zlib or raw deflate, as text, Base64 or hex, with levels 1 to 9.

loading Gzip text compressor
About this tool

What is gzip, and what does this tool do?

Gzip is the most common way to shrink data on the web and on servers. A .gz file, an HTTP response with Content-Encoding: gzip, a compressed log, and many API payloads use it. Under the hood it is the DEFLATE algorithm, wrapped in a small header and a checksum. DEFLATE appears in three forms that are easy to mix up: gzip (header 1f 8b, plus a CRC-32 and the original size), zlib (a two-byte header such as 78 9c and an Adler-32 checksum) and raw deflate (the bare compressed data, with no header at all). Libraries and protocols pick different ones, which is why "it does not decompress" is such a common problem.

This tool compresses and decompresses text or bytes with all three, in your browser. You can type text or paste Base64 or hex, choose a level from 1 (fastest) to 9 (smallest), and get the result as Base64 or hex, or download it as a file. When you decompress, it looks at the first bytes, tells you whether the data is gzip, zlib or raw deflate, and decompresses it on its own. It also shows the sizes before and after and the ratio.

Nothing is uploaded. The compression runs locally with a small JavaScript library, and the text you type is neither stored nor placed in the address bar.

How to compress and decompress

  1. Open the page. It starts in "Compress" with a repeated sentence, so you can see the effect on size at once.
  2. Pick the format: gzip, zlib or deflate, and the level. Level 6 is the usual balance; 9 gives the smallest output and takes a bit longer.
  3. Choose how the result is written: Base64 is compact and safe to paste; hex lets you read the header bytes.
  4. Press Copy, or use "Download .gz" to get a real file that other tools can open.
  5. To go the other way, switch to "Decompress", paste Base64 or hex, and leave the format on Auto. The status line names the format it found.
  6. If the output is not text, the tool says so and shows the bytes in hex.

Examples

A Base64 string that starts with H4sI

Gzip data in Base64 always starts with H4sI, because the bytes 1f 8b 08 encode to those four letters. Paste such a string into "Decompress" and the original text appears. For example, H4sIAAAAAAAAA8tIzcnJVyjPL8pJAQCFEUoNCwAAAA== decompresses to hello world.

Telling zlib from gzip

Data that begins with 78 9c (Base64 eJ) is zlib; 78 01 and 78 da are zlib at the fastest and the best levels. Data that begins with 1f 8b is gzip. If neither header matches, the tool tries raw deflate before giving up.

How much does it save?

Repeated text compresses very well: a sentence repeated forty times shrinks to a few dozen bytes. Short strings can become larger, because the header and checksum take about 18 bytes in gzip and 6 in zlib. Compressing a ten-character word is not worth it.

Moving between systems

Compress in the browser with gzip, copy the Base64 and decode it in a script with base64 -d | gzip -d, or the other way around. The output of this tool is read by Python's gzip module, Node's zlib and the gzip command, and it reads their output too.

Common mistakes

  • Pasting the Base64 of the wrong thing. If the data is not gzip, zlib or deflate, the tool says so. Check that you pasted all of it and that "input as" matches what you pasted (Base64 or hex).
  • Truncated data. A stream that starts correctly but ends early is reported as damaged. This often happens when a log line is cut at a character limit.
  • Compressing already compressed data. Images, ZIP files and videos barely shrink, and may grow. Compress text, JSON, CSV, logs and source code.
  • Confusing compression with encryption. Gzip hides nothing; anyone can decompress it. Use encryption if the content is secret.
  • Expecting Brotli. Brotli (Content-Encoding: br) is a different format and is not supported here.

Frequently asked questions

Is my text sent to a server?

No. Compression and decompression run in your browser, and the page makes no request with your data.

Why is the compressed Base64 longer than my text?

Base64 adds about a third to the size, and the gzip header is fixed. For short text both effects dominate. Switch to hex or download the file to see the real byte count in the status line.

Will the output be the same every time?

Yes. The gzip header has no timestamp here, so the same text and level always give the same bytes. Other tools may write the current time in the header, so their output differs even for the same text; both decompress correctly.

What is the difference between the levels?

They trade time for size. Level 1 is fastest and largest, level 9 is slowest and smallest. For small inputs the difference is a few bytes.

What can I do with the bytes afterwards?

Convert them with the Base64 tool or look at them with the text and hex converter.

Report a problem