🔐 Z85 Encoder – ZeroMQ RFC 32 Binary-to-Text Encoding
Z85 is a binary-to-text encoding scheme standardized in ZeroMQ RFC 32. It converts arbitrary binary data into a compact stream of printable ASCII characters by encoding every 4 bytes of input into 5 ASCII characters. This yields exactly 25% overhead — significantly less than Base64's 33% overhead — making Z85 the preferred encoding for binary data in text-based protocols, configuration files, and messaging systems.
How Z85 Encoding Works
The Z85 algorithm processes input in 4-byte blocks:
- Each 4-byte chunk is interpreted as a 32-bit big-endian unsigned integer.
- That integer is expressed as five base-85 digits (most significant first) by repeatedly dividing by 85.
- Each digit (0–84) is mapped to a character in the Z85 alphabet.
The encoding formula for one block:
value = b0×256³ + b1×256² + b2×256 + b3
c0 = alphabet[(value / 85⁴) % 85]
c1 = alphabet[(value / 85³) % 85]
c2 = alphabet[(value / 85²) % 85]
c3 = alphabet[(value / 85 ) % 85]
c4 = alphabet[(value ) % 85]
Output: c0 c1 c2 c3 c4 (5 chars per 4-byte block)The Z85 Alphabet
Z85 uses 85 carefully selected printable ASCII characters that are safe in shell scripts, JSON, YAML, XML, and most programming environments:
0123456789abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZz.-:+=^!/*?&<>()[]{}@%$#The alphabet deliberately avoids ', ", \, and whitespace characters that would require escaping in most contexts.
Z85 vs Other Encodings
Z85 vs Base64
For 100 bytes of input: Base64 produces ~136 characters (33% overhead), Z85 produces 125 characters (25% overhead). Z85 output is approximately 8% smaller than Base64, and its character set is more shell- and URL-friendly without encoding.
Z85 vs ASCII85
ASCII85 (Adobe variant) uses characters ! to u and wraps output in <~ ~> delimiters. Z85 uses an alphanumeric-first alphabet and has no delimiters. Z85 is designed for modern protocols; ASCII85 is legacy PostScript/PDF.
Overhead Comparison Table
| Scheme | Input Bytes | Output Chars | Overhead |
|---|---|---|---|
| Z85 | 4 | 5 | 25% |
| Base64 | 3 | 4 | 33% |
| Base32 | 5 | 8 | 60% |
| Hex | 1 | 2 | 100% |
Key Constraint: Input Must Be a Multiple of 4 Bytes
Unlike ASCII85, Z85 does not define a mechanism for partial final blocks. The input byte count must be exactly divisible by 4. This tool automatically zero-pads your input when needed and shows you how many padding bytes were added. Common inputs that naturally align to 4 bytes include:
- Curve25519 public keys — 32 bytes → 40-character Z85 string
- UUIDs / GUIDs — 16 bytes → 20-character Z85 string
- SHA-256 hashes — 32 bytes → 40-character Z85 string
- AES-128 keys — 16 bytes → 20-character Z85 string
UUID Shortening with Z85
A standard UUID (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) is 36 characters. By decoding it as 16 raw bytes and encoding with Z85, you get a 20-character compact representation — saving 44% of space. This is useful for compact database keys, URL path segments, or CLI argument identifiers.
Real-World Use Cases
ZeroMQ Curve25519 Keys
ZeroMQ's CURVE security mechanism uses Z85 to represent 32-byte Curve25519 public and private keys as 40-character ASCII strings. These can be safely included in configuration files and command arguments without escaping.
Binary Identifiers in APIs
Random nonces, session tokens, and correlation IDs are often 16 or 32 bytes of cryptographic data. Z85-encoding them produces compact, readable strings for API responses, log entries, and HTTP headers.
Configuration Files
Embedding cryptographic certificates, tokens, or binary blobs in YAML/TOML/JSON configuration files is cleaner with Z85 than with hex — strings are shorter and avoid the quoting issues of Base64's +, /, and = characters.
Tips for Using This Tool
- Use Plain Text mode for quick experiments — the tool auto-pads your input to 4-byte alignment.
- Use Hex String mode to encode exact byte sequences such as cryptographic keys or hash digests.
- Use UUID / GUID mode to generate compact 20-character identifiers from standard UUIDs.
- Enable Auto Encode to see the Z85 output update in real time as you type.
- Toggle Show Alphabet to display the full Z85 character set with index values for reference.
- The Block Mapping table shows up to 8 input blocks with their hex bytes and corresponding Z85 output — useful for learning and debugging.