Skip to content

Gzip Compress & Decompress

Compress UTF-8 text into Base64-wrapped RFC 1952 gzip bytes or decompress gzip Base64 back to strictly valid UTF-8 text.

Privacy: your files never leave your device. All processing happens locally in your browser.

How to use

  1. 1.Choose UTF-8 text to gzip Base64, enter text, and compress; copy the complete padded Base64 result.
  2. 2.To reverse it, choose Gzip Base64 to UTF-8, paste a canonical Base64 string containing an RFC 1952 gzip stream, and decompress.
  3. 3.Verify the restored text and confirm the target system expects this exact container; use a binary gzip tool when the payload is not UTF-8 text.

About Gzip Compress & Decompress

Gzip Compress and Decompress converts UTF-8 text to a gzip byte stream displayed as canonical Base64, or takes Base64-wrapped gzip bytes and restores UTF-8 text. It uses the browser Compression Streams API, runs locally, and offers a copy action for either result. The wrapper makes arbitrary compressed bytes practical to paste into a text field.

Gzip is a lossless container defined by RFC 1952. A stream begins with magic bytes 1f 8b and a compression method value of 8 for DEFLATE. It carries header fields, compressed blocks, and an eight-byte little-endian trailer containing CRC32 of the uncompressed bytes and ISIZE, the input size modulo 2^32. The browser creates and validates this framing.

Compression first converts the entered string to UTF-8 bytes. Non-ASCII characters can take several bytes, so byte size is not the same as visible character count. The CompressionStream receives those bytes and produces a standards-compatible gzip stream. The tool then encodes that binary stream as padded Base64 without inserting spaces, line wraps, a data URL prefix or a filename.

Decompression first applies strict RFC 4648 Base64 decoding. Missing padding, whitespace, invalid alphabet characters and nonzero pad bits are rejected. It then checks the minimum gzip framing and magic before passing bytes to DecompressionStream. The browser verifies the compressed stream and trailer; corrupt or incomplete input returns an error instead of partial text.

The decompressed bytes must form valid UTF-8. Gzip can contain any binary file, but this page is intentionally a text workflow. If a valid gzip stream expands to an image, archive, executable or legacy-encoded document, the strict decoder reports that it is not UTF-8 rather than replacing bytes or corrupting the output. Use a binary file decompressor for those cases.

Compressed output is not deterministic at the byte level across all encoders because header fields, DEFLATE choices and compression levels can differ while representing the same content. This tool does not assert one exact compressed Base64 string. Instead, tests assert RFC magic and method bytes, decompress the stream, and independently inspect trailer CRC32 and ISIZE against external check values.

Compression is not encryption, secrecy, authentication or sanitization. Gzip often makes text less readable but anyone can decompress it. Do not treat the result as protection for credentials or personal data. Gzip CRC32 detects accidental corruption and is not a cryptographic integrity guarantee against an attacker.

Both input and decompressed output are limited to 5,000,000 bytes. This guards against accidental large pastes and decompression expansion that could freeze the tab. Output is never silently truncated. The interface cancels stale asynchronous results when the mode or input changes, so an older compression job cannot overwrite a newer value.

Eight fixtures cover empty and short strings, common CRC suites, 123456789 and the quick-brown-fox sentence. For every case, the test reads the gzip trailer as little-endian, checks CRC32 and exact UTF-8 byte length, verifies magic and CM=8, and performs real decompression. This proves independent framing invariants in addition to round-trip behavior.

Use compression when another system explicitly expects gzip bytes or you need a compact text payload wrapped for transfer. Confirm whether the destination expects raw gzip, Base64 gzip, a Content-Encoding header, or a .gz file; those are different containers. When decompressing, paste only the Base64 payload, copy the restored text, and validate semantics in the application that defines the content.

Methodology & sources

UTF-8 bytes flow through CompressionStream('gzip') and the binary result is canonical Base64. Reverse mode strictly decodes Base64, checks gzip magic/CM=8, uses DecompressionStream, caps expansion, and fatal-decodes UTF-8.

Frequently asked questions

Encoding & Crypto guides

View all