How to gzip text online
To gzip compress online, type or paste text and the compressed data appears at once. The text is turned into UTF-8 bytes, compressed with the deflate method and wrapped in the gzip format. You can copy it as Base64 or hex, or download it as a .gz file that any gzip program opens.
How much it shrinks depends on the data. Take a JSON array of 200 small objects shaped like {"id":0,"name":"item 0","active":true}, 8,481 bytes long in all. At level 6 it compressed like this:
- gzip: 1,007 bytes, 88.1% saved
- zlib: 995 bytes, 88.3% saved
- raw deflate: 989 bytes, 88.3% saved
The three formats hold the same compressed data. The small differences are the size of the header and the checksum around it.
Gzip, zlib or raw deflate
Pick the format the other side expects. If you are not sure, gzip is the safest choice.
- gzip is the .gz format. HTTP uses it for Content-Encoding: gzip, and the gzip command and most languages read it.
- zlib has a two-byte header and an Adler-32 checksum. It is used by PNG, Git objects and many libraries, where the code calls it deflate.
- Raw deflate has no header and no checksum. Use it for ZIP internals and for protocols that ask for it by name.
Mixing them up is a common cause of errors such as incorrect header check. The Gzip Decompress tool detects all three from the first bytes.
Compression levels
Level 1 is the fastest and level 9 searches hardest for savings. The default, 6, is a balance. On large text the gap between levels is often small, and on small input it can be nothing, so try two levels and read the Saved line before choosing.
The level changes only the size and the time, never the content. Any level decompresses with any gzip program.
Gzip to Base64 and hex output
Compressed data is binary, so putting it in JSON, an environment variable, a config map or a URL needs a text form. Base64 is the usual one, and gzip Base64 strings start with H4sI. Base64 URL-safe swaps the two symbols that break URLs and drops the padding. Hex doubles the size but is easy to read byte by byte.
Base64 makes the data about a third larger, so compressing text and then Base64-encoding it can be bigger than the original for short input. Use Download when you can keep the file as binary.
import base64, gzip
text = base64.b64encode(gzip.compress(data.encode("utf-8"))).decode("ascii")Store the file name and time, or keep output repeatable
A gzip header can hold the file name and the modified time. By default this tool leaves both empty and writes a zero time, so the same input always gives the same bytes, which is handy for tests and for comparing outputs.
Switch on Store name and time to write them. For an uploaded file the name and the file's modified time are used. For typed text the name is data.txt and the time is now. The option applies to gzip only, because zlib and raw deflate have no place for them.
Why a file can get bigger
Compression finds repeated patterns. Data that is already compressed, such as PNG and JPEG images, ZIP archives and MP4 video, has few patterns left, and random data has none. A gzip file also adds about 18 bytes of header and trailer, so a very small input can grow.
The built-in sample is a good example. The 169-byte JSON compresses to 152 bytes, only 10.1% saved. When the result is not smaller, the strip says so in red and you can skip compressing that data.
What the round-trip check proves
After compressing, the page decompresses its own result and compares it with your input, byte for byte. A pass means the compressed data can be read back to exactly what you gave it. The same library does both steps, so it catches mistakes in the output but does not replace a test in your own program. The format is the standard one, and the compressed bytes are also read by other gzip programs.
Limits: input up to 50 MB, or 20 million characters of typed text. Brotli, ZIP archives with several files and tar are not covered.
Privacy
Files you compress can be private. Everything runs in your browser and nothing is uploaded. The Privacy Policy explains what the site stores.
Related tools: Gzip Decompress, File to Base64, Base64 Encode and Text to Hex.