Last updated
What Is Base85 Encoding?
Base85 (also called Ascii85) is a binary-to-text encoding that uses 85 printable ASCII characters to represent binary data. It encodes every 4 bytes of input into 5 ASCII characters, achieving roughly 25% overhead — significantly more efficient than Base64's 33% overhead. This makes it attractive for embedding binary data in text formats where size matters.
Adobe invented Ascii85 for PostScript and PDF files. The RFC 1924 variant uses a slightly different alphabet designed for IPv6 address compression. Git also uses a Base85 variant for binary patch files.
Base85 vs Base64 vs Base32
| Encoding | Alphabet size | Overhead | Main use |
|---|---|---|---|
| Base32 | 32 chars | ~60% | TOTP keys, DNS |
| Base64 | 64 chars | ~33% | Email, JWTs, web |
| Base85 | 85 chars | ~25% | PDF, PostScript, Git patches |
How the Encoding Works
Base85 treats every 4 bytes as a 32-bit big-endian integer, then encodes it as 5 digits in base 85.
The alphabet used by Ascii85 is ASCII characters 33–117 (! through u).
A special case: if all 4 bytes are zero, the output is a single z character instead of !!!!!.
Input bytes: 0x4D 0x61 0x6E 0x20 (= "Man ")
32-bit value: 0x4D616E20 = 1298230816
Divide repeatedly by 85:
1298230816 / 85 = 15273303 r 1 → char 1+33 = '"'
15273303 / 85 = 179685 r 48 → char 48+33 = 'Q'
179685 / 85 = 2114 r 55 → char 55+33 = 'X'
2114 / 85 = 24 r 74 → char 74+33 = 'k'
24 / 85 = 0 r 24 → char 24+33 = '9'
Output (reversed): 9Xk"Q → but standard Ascii85 wraps in <~ ... ~>
Where You'll Find Base85
- PDF files: The
ASCII85Decodefilter in PDF streams uses Ascii85 to embed binary image data as printable text. - PostScript: Adobe's original use case — embedding fonts and images in PostScript documents.
- Git binary patches:
git diff --binaryuses a custom Base85 alphabet to encode binary file changes in patch files. - ZeroMQ: The Z85 variant is used to encode 256-bit keys in ZeroMQ's CURVE security mechanism.
Python Example
import base64
# Python's base64 module includes ascii85 support
data = b"Hello, World!"
encoded = base64.a85encode(data)
print(encoded) # b'87cURD]i,"Ebo80'
decoded = base64.a85decode(encoded)
print(decoded) # b'Hello, World!'
# For the b85 variant (used by Git/ZeroMQ):
encoded_b85 = base64.b85encode(data)
print(encoded_b85) # b'NM&qnZ!92pZf0l9'