Base64 encode/decode · Guide
Base64 Decode and Unzip: Handling Compressed Payloads
Compressed-then-encoded payloads are common wherever data must be small and text-safe: SAML assertions, API responses, log shipping, cookies. Unwrapping one means doing two steps in the right order.
The order matters
Data is compressed first, then Base64-encoded — because compression produces binary and Base64 makes binary text-safe. Unwrapping therefore reverses it: decode first, decompress second.
Doing it the other way round fails immediately, since a Base64 string is text and gzip will not recognise it.
Recognising what you have
Decode and look at the first bytes. 1F 8B is gzip. 50 4B 03 04 is a ZIP container. 78 9C or 78 DA is raw zlib/deflate, which is what SAML and many cookies use — and which needs inflate, not gunzip.
The distinction between gzip and raw deflate causes most of the failures here: they are related formats with different headers, and using the wrong one gives an unhelpful error.
Doing it
# gzip
base64 -d payload.b64 | gunzip
# ZIP archive — needs a real file
base64 -d payload.b64 > archive.zip && unzip archive.zip
# raw deflate (SAML, cookies)
base64 -d payload.b64 | python3 -c \
"import sys,zlib; sys.stdout.write(zlib.decompress(sys.stdin.buffer.read(), -15).decode())"The -15 window argument is what selects raw deflate with no header. Omit it and zlib expects its own header, which SAML payloads do not have.
Going the other way
To produce such a payload, compress then encode — and note the ordering interacts with encryption. If data must be both compressed and encrypted, compress first, encrypt second, encode last.
One caveat worth knowing: compressing attacker-influenced data together with a secret leaks information through the compressed length. That is the basis of the CRIME and BREACH attacks, and it is why some protocols disabled compression entirely.
Frequently asked questions
Decode or decompress first?
Decode first. The Base64 layer is always outermost.
gunzip says "not in gzip format" — why?
The payload is probably raw deflate or zlib, not gzip. Check the first bytes: 1F 8B is gzip, 78 9C is zlib.
Does compressing before Base64 save space?
Usually yes. Compression typically shrinks data far more than the 33% Base64 adds back.
Ready to try it?
Open the free browser-based Base64 encode/decode and apply what you just read — no sign-up, runs locally.
Open the Base64 encode/decode tool