All operations

ASCII85

Four bytes packed into five printable characters.

Four bytes, five characters

Each group of four bytes is read as one 32-bit number and written in base 85, using the printable characters from ! through u. Five characters carry four bytes, so encoded data is 25% larger than what went in. Base64 costs 33% for the same job.

Why 85

Eighty-five is the smallest base that fits a 32-bit number into five digits. That range runs to 4,294,967,296 values. Five base-85 digits give 4,437,053,125, which covers it; base 84 manages 4,182,119,424 and falls short. One packing works.

The text above

That passage is an abridged sentence from chapter 6 of Hobbes’s Leviathan, published in 1651, and it is the worked example nearly every ASCII85 write-up quotes, so the output can be checked against them character for character. It ends /c~>. The delimiter switch is on, which is why it opens with <~.

Shortcuts and short groups

Four zero bytes become the single character z, which saves a great deal of space in a PDF carrying zeroed image data. The shortcut applies only to a complete group.

A final group of one, two or three bytes is padded with zeros, encoded to five characters, then truncated by the number of bytes that were missing. The length survives without any padding character, and the decoder reverses the trick by filling the short group out with u and dropping the same count off the end.

The format started as Paul Rutter’s btoa, whose version 4.2 added y for a group of four spaces. This decoder rejects y by name, along with anything outside ! to u.

Delimiters

Inside a PDF the trailing ~> is the end-of-data marker for the ASCII85Decode filter, and Adobe’s convention allows an opening <~ in front of the payload. Decoding here strips either marker when present and works with neither, so a fragment lifted straight out of a stream goes in as it stands.

Why Base64 won anyway

The alphabet is the reason. ASCII85 output contains ", ', \, <, >, & and %, and every one of those needs escaping somewhere: JSON strings, XML bodies, shell arguments, URLs. Eight percentage points of size is a cheap price for never quoting anything.

It survived in the formats that control their own container, chiefly PostScript and PDF streams. Git’s binary patches use a base-85 variant with its own alphabet, and ZeroMQ’s Z85 reshuffles the characters again so the result can be pasted into source code.

Base64 gives up the density for an alphabet nothing has to escape. Quoted-printable goes the other way, expanding only the bytes that would not survive the trip.