How to encode and decode Ascii85
- Type or paste text into Input · Text. The Ascii85 appears in Output · Ascii85 (Adobe).
- Under the output, tick Add <~ ~> delimiters for the PostScript/PDF framing, and untick z for zero groups if your decoder does not support the shortcut.
- To use another Base85 alphabet, change To to Base85 (Git / Python b85), Z85 (ZeroMQ) or RFC 1924 (IPv6 Base85).
- To decode, click Ascii85 (Adobe) → Text in the direction toggle. The decoder accepts the
<~ ~>delimiters,z,yand any whitespace, so line-wrapped data from a file pastes straight in. - For binary results, set To to Hex or click Save bytes.
How Ascii85 works
Ascii85 takes 4 bytes at a time, reads them as one 32-bit big-endian number and writes it as 5 base-85 digits. Each digit is a character from ! (value 0) to u (value 84). Five characters for four bytes is a 25% overhead, against 33% for Base64.
The classic example is Man (with the trailing space): the bytes 4d 61 6e 20 become 9jqo^. When the last group is short, the encoder pads it with zero bytes and writes only n + 1 characters for n bytes, so Hello (5 bytes) becomes 87cURDZ: five characters for Hell and two for o.
Two shortcuts shorten common patterns. z replaces a group of four zero bytes, which is !!!!! written out. y replaces four spaces in the btoa variant. This decoder reads both, and the encoder writes z (switchable) but never y.
Base85 variants compared
| Variant | Alphabet | Hello | Where it is used |
|---|---|---|---|
| Ascii85 (Adobe) | ! to u in ASCII order | 87cURDZ | PostScript, PDF /ASCII85Decode |
| Base85 (Git / Python) | 0-9 A-Z a-z !#$%&()*+-;<=>?@^_`{|}~ | NM&qnZv | Git binary patches, Python base64.b85encode |
| Z85 | 0-9 a-z A-Z .-:+=^!/*?&<>()[]{}@%$# | nm=QNzV | ZeroMQ and CurveZMQ keys, see Z85 |
| RFC 1924 | Same as Git | 4)+k&C#VzJ4br>0wv%Yp for one IPv6 address | IPv6 addresses, as a joke |
The Git and RFC 1924 alphabets are the same, but RFC 1924 treats a whole 16-byte address as one 128-bit number instead of four 4-byte groups. RFC 1924 was published on 1 April 1996 and proposes writing 1080::8:800:200c:417a as 4)+k&C#VzJ4br>0wv%Yp. The converter reproduces it with From set to IPv6 address and To set to RFC 1924 (IPv6 Base85).
Ascii85 in PDF and PostScript
PostScript Level 2 introduced Ascii85 for embedding binary data, such as images and fonts, in a text file. The data is framed as <~ … ~>. In PDF, a stream with /Filter /ASCII85Decode holds the same encoding, terminated by ~>. The decoder here finds the end marker with or without the opening <~.
Ascii85 is often the outer filter of a chain, for example /Filter [/ASCII85Decode /FlateDecode]. Decoding the Ascii85 then gives zlib-compressed bytes rather than readable content.
Git uses Base85 differently. In a GIT binary patch, each line starts with one length character (A–Z for 1–26 bytes, a–z for 27–52), followed by Base85 of the zlib-compressed data. Remove that first character from every line before decoding, then inflate the result.
Ascii85 and Base85 in Python
The standard library has both alphabets:
import base64
base64.a85encode(b"Hello") # b'87cURDZ'
base64.a85encode(b"Hello", adobe=True) # b'<~87cURDZ~>'
base64.a85encode(b" ", foldspaces=True) # b'y'
base64.b85encode(b"Hello") # b'NM&qnZv'
base64.a85decode(b"<~9jqo^~>", adobe=True) # b'Man '
a85decode needs adobe=True to accept the delimiters. See the Python page for more encoding recipes.
Common problems
"z" at position … is only allowed between 5-character groups. Azappears inside a group. The data is damaged, or it is not Ascii85; Z85 and Git’s Base85 usezas an ordinary digit.the group starting at position … is out of range. Five characters encode a value above 2^32 − 1. This happens when Git Base85 or Z85 is decoded as Ascii85; switch From.- Unexpected character such as
v,{or|. Everything afteruexcept theyandzshortcuts is outside the Ascii85 alphabet, another sign of a different variant. - The output has extra zero bytes at the end. Your encoder padded the last group and wrote all 5 characters. Ascii85 writes n + 1 characters for a final group of n bytes.
FAQ
What is the difference between Base85 and Ascii85?
Base85 is the general idea of writing 4 bytes as 5 characters from an 85-character set. Ascii85 is Adobe’s version, with the characters ! to u, the z shortcut and <~ ~> delimiters. Git, Python’s b85encode, Z85 and RFC 1924 use the same arithmetic with other alphabets.
What does z mean in Ascii85?
A single z stands for four zero bytes, which would otherwise be written !!!!!. It is only allowed where a full 5-character group would start; a z inside a group is an error.
How do I decode Ascii85 from a PDF?
Copy the stream data between stream and endstream up to and including ~>, and paste it with the direction set to Ascii85 (Adobe) → Text. If the stream also lists /FlateDecode, the result is zlib data; set To to Base64 and inflate it with the gzip and zlib decoder.
Is Base85 better than Base64?
It is about 6% shorter: 25% overhead against 33%. But its alphabets include quotes, backslashes or < and &, depending on the variant, so it needs escaping in JSON, XML or shell where Base64 does not. Use it where those characters are safe.