PureDevTools

Gzip Compress / Decompress

Compress and decompress text or files with Gzip — see compression ratio instantly

All processing happens in your browser. No data is sent to any server.

Input Source

Enter text above and click Compress to gzip it. The result is available as Base64 and a downloadable .gz file.

Browser Compatibility

This tool uses the native CompressionStream/DecompressionStream API. Supported in Chrome 80+, Edge 80+, Safari 16.4+, and Firefox 113+. All processing happens locally in your browser — no data is sent to any server.

You’re building an API and want to test whether your JSON response compresses well before configuring Content-Encoding: gzip on the server. Or you received a .gz file from a colleague and need to peek inside without installing anything. Or you’re optimizing your website’s transfer size and want to see the actual gzip ratio for your HTML, CSS, or JavaScript bundles — not just the theoretical estimate from a build tool.

Why This Tool (Not gzip on the Command Line)

The gzip command is available on Linux and macOS but not on every machine — especially not on shared workstations, locked-down corporate laptops, or Chromebooks. And running gzip -c file.json | wc -c requires a terminal and some shell fluency. This tool runs entirely in your browser using the Compression Streams API, showing both the original and compressed sizes with the compression ratio. No installation, no server upload, instant results.

What Is Gzip?

Gzip (GNU zip) is a compression algorithm and file format defined in RFC 1952. It uses the DEFLATE algorithm (RFC 1951) — a combination of LZ77 and Huffman coding — to reduce data size. Gzip adds a thin wrapper around DEFLATE with a file header (magic number, timestamp, OS) and a CRC32 checksum for integrity verification.

Gzip is the dominant compression format on the web:

How Gzip Compression Works

Gzip compression applies two algorithms in sequence:

1. LZ77 (Sliding Window)

LZ77 scans the input for repeated sequences and replaces them with back-references. For example, if the string "the quick brown fox and the quick red fox" contains "the quick " twice, the second occurrence is replaced with a pointer: “go back 27 characters, copy 10 characters.”

The sliding window is typically 32 KB — the algorithm looks back up to 32,768 bytes for matches.

2. Huffman Coding

After LZ77, the remaining bytes and back-references are encoded using Huffman coding, which assigns shorter bit patterns to more frequent values. A byte that appears 1,000 times might get a 3-bit code, while a byte that appears once gets a 15-bit code.

The result: highly repetitive data (like HTML templates, JSON responses, or log files) compresses extremely well, while already-compressed data (JPEG, MP4, ZIP) barely compresses at all.

Compression Ratios by Content Type

Content TypeTypical Gzip RatioWhy
HTML70–85% reductionHighly repetitive tags and structure
CSS75–85% reductionRepetitive property names and values
JavaScript60–75% reductionVariable names, keywords, repeated patterns
JSON70–90% reductionRepeated keys, structural characters
Plain text50–70% reductionNatural language has moderate redundancy
PNG / JPEG0–5% reductionAlready compressed; gzip can’t improve
Binary / random0–2% reductionNo patterns to exploit

Gzip in HTTP: Content-Encoding

The most common use of gzip is HTTP transfer compression. Here’s the exchange:

# Request
GET /api/data HTTP/1.1
Accept-Encoding: gzip, deflate, br

# Response
HTTP/1.1 200 OK
Content-Encoding: gzip
Content-Type: application/json
Content-Length: 1234

[gzip-compressed body]

The browser automatically decompresses the response — the JavaScript application sees the original JSON, never the compressed bytes.

Server Configuration

# Nginx
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml;
gzip_min_length 256;
gzip_comp_level 6;
# Apache
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json application/javascript
// Node.js / Express
const compression = require('compression');
app.use(compression());

Gzip vs Brotli vs Zstd

AlgorithmCompression RatioSpeedHTTP SupportUse Case
GzipGoodFastUniversalDefault web compression
BrotliBetter (10–20% smaller)Slower to compressModern browsersStatic assets, HTTPS only
ZstdBetterFaster than BrotliEmergingServer-to-server, CDNs

Gzip remains the safe default because every browser, CDN, and proxy supports it. Brotli offers better compression but is only available over HTTPS and requires more CPU for compression (decompression is fast). Zstandard (Zstd) is gaining adoption in CDNs and server-to-server communication.

Browser Implementation

This tool uses the Compression Streams API, available in all modern browsers (Chrome 80+, Firefox 113+, Safari 16.4+). The API provides native gzip compression and decompression without any JavaScript library:

// Compress with the Compression Streams API
async function gzipCompress(data) {
  const stream = new Blob([data]).stream()
    .pipeThrough(new CompressionStream('gzip'));
  return new Response(stream).arrayBuffer();
}

// Decompress
async function gzipDecompress(compressedData) {
  const stream = new Blob([compressedData]).stream()
    .pipeThrough(new DecompressionStream('gzip'));
  return new Response(stream).arrayBuffer();
}

Frequently Asked Questions

Does gzip compress images well? No. JPEG, PNG, WebP, and other image formats are already compressed. Gzip cannot find additional redundancy in them and typically adds a few bytes of overhead (the gzip header). Never gzip images for HTTP delivery — serve them directly or use a better image format.

What compression level should I use? For HTTP: level 6 is the default and offers the best balance of compression ratio and CPU usage. Levels 7–9 yield diminishing returns with significantly more CPU time. For static assets that are compressed once and served many times, level 9 is acceptable.

Is this tool private? Yes. All compression and decompression happens in your browser using the Compression Streams API. No data is sent to any server.

What is the difference between gzip and zip? Gzip compresses a single stream of data. ZIP is a container format that can hold multiple files, each independently compressed. The .tar.gz format uses tar to bundle multiple files, then gzip to compress the bundle.

Related Tools

More Encoding & Crypto Tools