Home › Developer Tools › Gzip Compress / Decompress

Gzip Compress / Decompress

Compress text or any file with gzip, zlib or raw deflate and get the result as Base64, hex or a .gz download. Paste a Base64 or hex gzip string, or drop a .gz file, to decompress it. Everything runs in your browser with the built-in CompressionStream API.

Last updated:

Advertisement
Advertisement

How to use the Gzip Compress / Decompress

  1. Choose Compress or Decompress and whether you are working with text or a file.
  2. Pick the format: gzip for .gz files and HTTP, zlib for many APIs and PNG-style streams, raw deflate for ZIP entries and some web APIs. Decompress can auto-detect it.
  3. Enter the data: type or paste text, paste a Base64 or hex string, or drop a file.
  4. Read the stats to see how much smaller the data got, and the gzip header details when decompressing.
  5. Copy or download the result: Base64 or hex text, a .gz file, or the decompressed file.

gzip vs zlib vs raw deflate

All three wrap the same DEFLATE compressed data (LZ77 plus Huffman coding, RFC 1951). They differ only in the header and checksum around it, so pick the one the receiving program expects:

FormatHeaderTrailerStarts withTypical use
gzip (RFC 1952)10 bytes + optional name, commentCRC-32 + original size (8 bytes)1F 8B · Base64 H4sI.gz and .tgz files, HTTP Content-Encoding: gzip
zlib (RFC 1950)2 bytesAdler-32 (4 bytes)78 9C, 78 01, 78 DA · Base64 eJPNG chunks, PDF streams, Python zlib, HTTP deflate
raw deflate (RFC 1951)nonenoneno fixed signatureZIP entries, WebSocket permessage-deflate, some APIs

Reading the compression stats

  • Ratio = compressed size ÷ original size × 100. 25% means the output is a quarter of the input.
  • Space saved = 100% − ratio.
  • Factor = original size ÷ compressed size, for example 4.00 : 1.
  • As Base64 shows the text length you would store or send: 4 × ⌈compressed bytes ÷ 3⌉ characters. Gzip plus Base64 only pays off when compression saves more than about 25%.

Equivalent commands

To reproduce or check results on the command line:

  • Compress to Base64: gzip -c file.txt | base64
  • Decompress Base64: echo 'H4sI…' | base64 -d | gunzip
  • Python: gzip.compress(data), zlib.compress(data), or zlib.compressobj(wbits=-15) for raw deflate
  • JavaScript: pipe blob.stream() through new CompressionStream('gzip') and read it with new Response(stream).arrayBuffer()

Frequently asked questions

How do I decompress a gzip Base64 string?

Choose Decompress, keep the input on Text and paste the Base64 string. The tool decodes the Base64, recognises the gzip header (it starts with H4sI in Base64, which is the bytes 1F 8B), inflates it and shows the text. If the result is binary, use the download button to save it as a file.

What is the difference between gzip, zlib and deflate?

All three use the same DEFLATE compression algorithm (RFC 1951). Raw deflate is the bare compressed stream. Zlib (RFC 1950) adds a 2-byte header and an Adler-32 checksum. Gzip (RFC 1952) adds a 10-byte header with optional file name and timestamp, plus a CRC-32 and the original size at the end. The compressed data inside is identical.

Why is my compressed output bigger than the input?

Gzip adds about 18 bytes of header and trailer, and very short or random data has no repetition to remove. Text under roughly 100 bytes, already compressed files such as JPEG, MP4 or ZIP, and encrypted data usually do not shrink. Base64 then adds another 33% because it uses 4 characters per 3 bytes.

How much does gzip compress text?

It depends on how repetitive the data is. Typical HTML, CSS, JavaScript and JSON shrink to about 15% to 30% of their size, plain English prose to about 35% to 45%. The stats panel shows the exact ratio for your data.

What do the compression levels do?

Level 1 is fastest with larger output, level 9 tries hardest for the smallest output, and 6 is the gzip default. The browser's native CompressionStream does not let you choose a level, so selecting a number loads the small pako library to compress instead. Any level can be decompressed by any gzip tool.

Why does decompression fail with an error?

Common causes are a Base64 string that was cut off or wrapped with extra characters, data that is actually a ZIP archive (starting with PK, use an unzip tool instead), the wrong format selected (try Auto-detect), or a stream that is not compressed at all. The tool shows the first bytes it found to help you check.

Is my data uploaded?

No. Compression and decompression use your browser's CompressionStream and DecompressionStream APIs (or the pako library for levels), so text and files stay on your device.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

Base64 Encoder DecoderEncode or decode Base64 text and files, and make data URIs.ZIP File CreatorCompress files and folders into a ZIP.Unzip FilesOpen and extract ZIP files online.File to Base64Convert any file to a Base64 string or data URI with MIME detection, line wrap and download.DMARC Report AnalyzerRead DMARC aggregate XML reports (.xml, .gz, .zip): sources, SPF/DKIM alignment and pass rates.SAML DecoderDecode SAMLRequest and SAMLResponse messages to readable XML, attributes and validity times.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.JavaScript BeautifierFormat and beautify messy or minified JavaScript, or minify it.HTML FormatterBeautify and indent HTML code with a live preview.CSS FormatterBeautify CSS with indent controls and optional property sorting.XML FormatterBeautify, validate and minify XML with a collapsible tree view.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.HTML MinifierMinify HTML: strip comments and whitespace safely and see how many bytes you save.CSS MinifierMinify CSS with csso or a built-in engine and see the size saved instantly.JavaScript MinifierMinify JavaScript with Terser: compress, mangle and see how many bytes you save.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.Code Diff CheckerCompare two code files side by side or unified, with syntax colors and changes highlighted.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.GraphQL FormatterPretty-print and indent GraphQL queries, mutations and schemas, or minify them, instantly.CSS ValidatorValidate CSS: syntax errors, unknown properties and invalid values by line, plus auto-fix.IBAN ValidatorCheck an IBAN's mod-97 checksum, country and length, and see its bank code and account parts.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JSON Schema ValidatorValidate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with clickable error paths.Markdown FormatterBeautify Markdown with Prettier: list markers, prose wrap, aligned tables and live preview.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.TypeScript FormatterFormat TypeScript and TSX code with Prettier: width, tabs, semicolons and quotes options.XML MinifierMinify and validate XML: strip whitespace and comments, keep CDATA, see the size savings.C# FormatterBeautify C# code online: Allman or K&R braces, indent size and line width, clang-format option.HTML ValidatorCheck HTML for errors and warnings with line numbers, locally or with the W3C Nu checker.Java FormatterBeautify Java code online: indent size, brace style and line width, with clang-format option.JavaScript ObfuscatorObfuscate JavaScript with string encoding, renaming and control-flow flattening presets.Phone Number FormatterFormat and validate lists of phone numbers to E.164, international or national style.Python FormatterFormat Python code in Black/Ruff style: line length, quote style, indent, copy or download.Responsive Design CheckerPreview any website at phone, tablet, laptop and desktop sizes side by side, with rotate and zoom.Browser Compatibility CheckerSearch CSS, JavaScript and HTML features and see which browser versions support them.Core Web Vitals CheckerCheck real-user LCP, INP and CLS for any URL or site and see if it passes Core Web Vitals.Heading Structure CheckerPaste HTML to see its H1-H6 outline and catch missing H1s, multiple H1s and skipped levels.Website Hosting CheckerFind out who hosts a website: hosting provider, IP addresses, ASN, network owner and location.Routing Number ValidatorCheck a US ABA routing number's checksum and format and see its Federal Reserve district.Spam Word CheckerScan an email subject and body for spam trigger words, excess caps, exclamation marks and risky links.Check Digit CalculatorCalculate or validate check digits for UPC, EAN, GTIN, SSCC, ISBN, ISSN and mod 11 codes.Luhn Algorithm CheckerValidate numbers with the Luhn mod 10 check or calculate the missing check digit, step by step.XSD ValidatorValidate XML against an XSD schema in your browser and see each error with its line number.Strftime Format BuilderBuild Python and C strftime format strings by clicking tokens, with a live preview and reference.
See all 41 Code Formatters & Validators →