FormatterHQ

Zlib Compress

Compress text with zlib (DEFLATE plus a small header and Adler-32 checksum) and get the bytes as Base64 or hex for embedding in code, JSON or protocols.

Input TEXT
Output TEXT
Ready.

How to use the Zlib Compress

  1. Paste the text you want to compress into the input editor, upload a file, or click Sample to load an example.
  2. Set the Level from 1 to 9 and choose Base64 or Hex Output.
  3. Click Compress in the options panel. With Auto update ticked, the result refreshes as you type.
  4. Copy the result from the output panel or download it as a file.

Zlib compress for embedded data

Zlib (RFC 1950) wraps DEFLATE-compressed data in a compact 2-byte header and a 4-byte Adler-32 checksum. It is the format used inside PNG images and PDF streams, by Git objects, by Python’s zlib.compress, PHP’s gzcompress and Java’s Deflater. This tool will zlib compress text and give you the bytes as Base64 or hex.

Example

Input (38 bytes):

Hello world! Hello world! Hello world!

Zlib, Base64 encoded:

eJzzSM3JyVcozy/KSVFU8MDFAQAGNw1Y

The same data at level 9 in hex: 78daf348cdc9c95728cf2fca495154f0c0c5010006370d58. Note the first byte 78: every zlib stream starts with it (for the default 32 KB window). The second byte encodes the compression level hint — 9C for the default and DA for the best compression — which is why zlib data in Base64 usually starts with eJ.

Zlib vs. gzip vs. raw DEFLATE

FormatHeader / trailerTypical use
Raw DEFLATENoneZIP entries, WebSocket permessage-deflate
Zlib2 bytes + Adler-32 (6 bytes)PNG, PDF, Git, application data
Gzip10 bytes + CRC-32 and size (18 bytes).gz files, HTTP compression

All three share the same compressed core, so compression ratios are nearly identical; zlib is simply smaller in overhead, which matters for short messages. When an HTTP server says Content-Encoding: deflate, it is supposed to mean zlib format, though some older servers sent raw DEFLATE.

When compression makes data bigger

Zlib always adds 6 bytes of header and checksum, and DEFLATE needs repetition to save space. Very short inputs therefore grow:

"Hi"  (2 bytes)
zlib: 78 9c f3 c8 04 00 00 fb 00 b2   (10 bytes)
Base64: eJzzyAQAAPsAsg==              (16 characters)

The last four bytes of any zlib stream are the Adler-32 checksum of the original data. In the example above, 06370d58 at the end of the level 9 output is the Adler-32 of the "Hello world!" text, which the decompressor recomputes to detect corruption. As a rule of thumb, compress only data of a few hundred bytes or more, or data with obvious repetition such as JSON with repeated keys; for tiny strings, Base64 alone is shorter.

Choosing a level

Level 6 is the zlib default. Level 9 squeezes out a little more at higher CPU cost, and level 1 is fastest. For text under a few kilobytes the differences are small; the status bar shows the exact sizes before and after compression.

Typical uses

  • Creating test data for code that calls a zlib or inflate function.
  • Shrinking large JSON or text before storing it in a cookie, a database field or a queue message, together with Base64.
  • Reproducing the output of PHP’s gzcompress or Python’s zlib.compress to debug an integration.

In code: Python zlib.compress(data, 9), Node.js zlib.deflateSync(buf), PHP gzcompress($s, 9). Base64-encode the result if it has to travel as text.

Decompress with Zlib Decompress, or use Gzip Compress if you need a .gz file. Everything runs in your browser.

Frequently asked questions

What is the difference between zlib and gzip?
Both compress with DEFLATE. Zlib adds a 2-byte header and an Adler-32 checksum, while gzip adds a larger header with a CRC-32 and the original size. Gzip is used for files and HTTP, zlib inside other formats.
Is this the same as PHP gzcompress?
Yes. PHP’s gzcompress produces zlib format, which matches this tool’s output at the same compression level. gzencode produces gzip and gzdeflate produces raw DEFLATE.
Why does zlib data start with eJ in Base64?
Zlib streams normally begin with the byte 0x78, and the first two bytes 78 9C (default compression) encode to eJ in Base64; 78 DA (best compression) gives eN, 78 01 gives eA and 78 5E gives eF.
Can compressed data be read by others?
Yes. Compression is not encryption; anyone can decompress the data. Encrypt sensitive data separately.

Last updated October 3, 2026

Related tools