Base85 (Z85) encoder and decoder
Base85 packs binary data more densely than Base64: every four bytes become five printable characters. This tool uses Z85, the ZeroMQ variant, whose 85-character alphabet avoids quotes and backslashes so the output is safe to embed in source code and config files.
How it works
To encode, your text is converted to UTF-8 bytes and processed in 4-byte
groups. Each group is read as a 32-bit big-endian number, then expressed in
base 85 as five digits, each mapped to a Z85 alphabet character. Because the
encoding needs whole 4-byte groups, input whose length is not a multiple of four
is padded with zero bytes (the tool reports how many). Decoding takes each
5-character block, rebuilds the 32-bit value (value = value × 85 + digit),
and splits it back into 4 bytes.
Why 85 is the magic number
Four bytes hold 256⁴ = 4,294,967,296 possible values. To encode that range in five characters, each character needs to cover at least ⁵√4,294,967,296 ≈ 84.4 values — so 85 is the smallest integer that works. Base64 handles only 3 bytes per 4 characters (a ratio of 4/3 ≈ 1.333 bytes per character), while Base85 handles 4 bytes per 5 characters (4/5 = 0.8 bytes per character represented as output characters, or more practically: Base64 expands data by 33%, Base85 expands it by only 25%).
Z85 vs Ascii85 — the two Base85 families
Z85 and Ascii85 (used in PostScript and PDF) are both Base85 encodings, but they are not interchangeable:
| Property | Z85 (ZeroMQ) | Ascii85 (PostScript/PDF) |
|---|---|---|
| Start/end markers | None | <~ … ~> |
| All-zero shorthand | None | z (single char = 5 zeros) |
| Alphabet | Safe for source code | Different character range |
| Defined in | ZeroMQ RFC 32 | Adobe PLRM / RFC 1924 |
Z85’s alphabet was chosen to exclude characters that would cause problems in C string literals, JSON, YAML, and XML — specifically no single quotes, double quotes, or backslashes. This makes it convenient for embedding keys and binary data directly in config files or source code without escaping.
Worked examples
Encoding the 4-byte text Gera:
Gera→ bytes47 65 72 61→m}DZH
| Bytes (hex) | Z85 |
|---|---|
47 65 72 61 (Gera) | m}DZH |
86 4F D2 6F | Hello (the official ZeroMQ Z85 test vector) |
Padding and what to watch for
If your input length is not a multiple of 4, this tool pads the end with zero bytes and tells you how many it added. When decoding, you need to know the original byte length to strip that padding correctly. If you are building a system that round-trips Z85, either store the original length separately or design your protocol so payloads are always a multiple of 4 bytes (e.g., by using a fixed-length structure or appending a 1-byte length indicator).
Everything runs in your browser — your input never leaves the page.