Base85 Encoding Explained: A More Compact Alternative to Base64
A comprehensive guide to Base85 (Ascii85) encoding: how it works, its 85-character alphabet, encoding and decoding algorithms, z zero compression, <~ ~> delimiters, and real-world applications in PostScript, PDF, Git, and beyond.
What is Base85?
Base85 is a highly efficient binary-to-text encoding scheme that uses 85 printable ASCII characters to represent arbitrary binary data. Its most well-known variant is Ascii85, originally developed by Paul E. Rutter in 1985 for the btoa utility and later adopted by Adobe for use in PostScript and PDF file formats — hence its common alias Adobe Ascii85.
The key advantage of Base85 over Base64 is its superior encoding efficiency: it encodes 4 bytes of binary data into just 5 characters, resulting in an overhead of only 25%, compared to Base64’s 33.3%. This means shorter output for the same amount of data — a meaningful advantage in bandwidth- and storage-sensitive scenarios.
Tool Recommendation: Need to encode or decode Base85? Try our online Base85 Encoder/Decoder with support for Text and Hex input,
<~ ~>delimiters, z zero compression, and more.
The Base85 Alphabet
Ascii85 uses 85 consecutive printable ASCII characters, ranging from code 33 (!) to code 117 (u), as its encoding alphabet:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstu
Each character’s index value is simply its ASCII code minus 33:
| Character | ASCII Code | Index |
|---|---|---|
! | 33 | 0 |
" | 34 | 1 |
# | 35 | 2 |
| … | … | … |
s | 115 | 82 |
t | 116 | 83 |
u | 117 | 84 |
Design Rationale: The range ASCII 33–117 avoids the space character (32) and DEL (127), as well as all non-printable control characters, while maximizing the number of usable characters for encoding efficiency.
How Base85 Works
Encoding (4 Bytes → 5 Characters)
Base85 encoding processes data in 4-byte (32-bit) groups:
- Read 4 bytes: Treat 4 consecutive bytes as a single 32-bit unsigned integer (big-endian)
- Base conversion: Repeatedly divide the integer by 85, collecting remainders
- Character mapping: Add 33 to each remainder to obtain the corresponding ASCII character
- Output 5 characters: Each 4-byte group produces exactly 5 encoded characters
Mathematical Basis: The maximum value of 4 bytes is 2³² − 1 = 4,294,967,295. Since 85⁵ = 4,437,053,125 > 4,294,967,295, five Base85 characters are sufficient to represent any 4-byte value.
Example: Encode the string “Man ” (with trailing space)
Bytes: 0x4D 0x61 0x6E 0x20
Integer: 1298230816 (decimal)
1298230816 ÷ 85 = 15273303 remainder 61 → chr(61+33) = '^'
15273303 ÷ 85 = 179685 remainder 78 → chr(78+33) = 'o'
179685 ÷ 85 = 2113 remainder 80 → chr(80+33) = 'q'
2113 ÷ 85 = 24 remainder 73 → chr(73+33) = 'j'
24 ÷ 85 = 0 remainder 24 → chr(24+33) = '9'
Reversed: 9jqo^
Trailing Byte Padding
When the input length is not a multiple of 4, the remaining bytes are zero-padded to form a complete 4-byte group for encoding. The extra encoded characters are then discarded:
| Remaining Bytes | Zero Padding | Encoded Chars | Output Chars |
|---|---|---|---|
| 1 | 3 | 5 | 2 |
| 2 | 2 | 5 | 3 |
| 3 | 1 | 5 | 4 |
During decoding, the symmetric approach is used: pad with u (index 84) to reach 5 characters, decode, then discard the extra bytes.
Decoding (5 Characters → 4 Bytes)
Decoding is the reverse of encoding:
- Read 5 characters: Map each character back to its index value (ASCII code − 33)
- Reconstruct the integer: value = c₀ × 85⁴ + c₁ × 85³ + c₂ × 85² + c₃ × 85¹ + c₄ × 85⁰
- Extract bytes: Split the 32-bit integer into 4 individual bytes
Special Features
<~ ~> Delimiters
The Adobe Ascii85 format uses <~ and ~> as boundary markers that wrap the encoded data. This clearly identifies the start and end of a Base85-encoded segment — essential in PostScript and PDF files where encoded data is embedded within other textual content.
Original data: Hello
Without delimiters: 87cURDZ
With delimiters: <~87cURDZ~>
z Zero Compression
When a complete 4-byte group consists entirely of zero bytes (i.e., the integer value is 0), Ascii85 can replace the five encoded characters !!!!! with a single character z. This zero compression can significantly reduce encoded size for data containing long runs of null bytes — such as blank regions in bitmap images.
Four zero bytes (00 00 00 00):
Standard encoding: !!!!! (5 characters)
Zero compression: z (1 character)
Note: The
zshorthand applies only to complete 4-byte groups. It cannot be used for trailing groups with fewer than 4 bytes.
Whitespace Handling
In practice, Base85-encoded data is often formatted across multiple lines (e.g., PostScript files limit lines to 80 characters). Decoders typically ignore whitespace characters (spaces, tabs, newlines) within the encoded data to correctly handle such formatting.
Encoding Efficiency Comparison
| Scheme | Input : Output | Overhead | Alphabet Size |
|---|---|---|---|
| Base85 | 4 : 5 | 25% | 85 |
| Base64 | 3 : 4 | 33.3% | 64 |
| Base62 | Big integer | ~37% | 62 |
| Base58 | Big integer | ~37% | 58 |
| Base32 | 5 : 8 | 60% | 32 |
| Base16 (Hex) | 1 : 2 | 100% | 16 |
Major Base85 Variants
1. Ascii85 (Adobe Variant)
- Character set: ASCII 33–117 (
!throughu) - Delimiters:
<~ ~> - Zero compression: Supported via
z - Usage: PostScript and PDF file formats
- Status: The most widely used variant, and the one implemented by our tool
2. Z85 (ZeroMQ Variant)
- Character set:
0-9a-zA-Z.-:+=^!/*?&<>()[]{}@%$#(a rearranged set of 85 characters) - Delimiters: None
- Zero compression: Not supported
- Usage: ZeroMQ message transport and network protocols
3. RFC 1924 Variant (IPv6)
- Character set:
0-9A-Za-z!#$%&()*+-;<=>?@^_{|}~ - Usage: Proposed compact representation for IPv6 addresses (an April Fools’ RFC, not widely implemented)
- Note: Encodes a 128-bit IPv6 address into 20 characters
4. btoa Original Format
- Character set: Same as Ascii85
- Delimiters:
xbtoa Beginandxbtoa End - Note: Includes checksum data; the predecessor of Ascii85
Common Use Cases
1. PostScript and PDF
The most important application of Base85 is in Adobe’s PostScript and PDF file formats. These formats need to embed binary data (images, fonts, embedded files) as text within the document stream. Base85 is more compact than both Base16 (Hex) and Base64, effectively reducing file size.
2. Git Binary Patches
The Git version control system uses Base85 encoding when generating patches for binary files. When git diff produces differences for binary files (e.g., images or compiled binaries), Git encodes the binary diff data in Base85 to embed it in text-based patch files.
3. Data Serialization and Transport
In scenarios requiring binary data transmission over text-only channels (JSON embedding, XML CDATA, config files), Base85 saves approximately 6% compared to Base64 — a difference that becomes more significant with larger payloads.
4. Network Protocols
ZeroMQ uses the Z85 variant to embed binary data in messages, ensuring encoded strings can be safely transmitted across various programming languages and transport protocols while maintaining high encoding efficiency.
5. Embedded Systems
In storage- and bandwidth-constrained embedded environments, Base85’s 25% overhead compared to Base64’s 33.3% can save valuable storage space and transmission bandwidth.
Comparing Base85 with Other Encodings
| Feature | Base85 | Base64 | Base62 | Base58 | Base91 |
|---|---|---|---|---|---|
| Alphabet Size | 85 | 64 | 62 | 58 | 91 |
| Overhead | 25% | 33.3% | ~37% | ~37% | ~14–23% |
| Encoding Unit | 4→5 | 3→4 | Big int | Big int | Bitstream |
| Special Symbols | Yes | Yes | No | No | Yes |
| URL Safe | ❌ | ❌ Needs variant | ✅ | ✅ | ❌ |
| Zero Compression | ✅ | ❌ | ❌ | ❌ | ❌ |
| Standardized | Adobe standard | RFC 4648 | None | None | None |
| Primary Use | PS/PDF/Git | General transfer | Short URLs/IDs | Crypto | Max compactness |
Implementation Considerations
-
Integer Overflow: The maximum intermediate value during encoding is 85⁵ − 1 = 4,437,053,124, which fits within JavaScript’s safe integer range (2⁵³). However, in C/C++ you should use unsigned 32-bit integers carefully.
-
z Character Position: The
zshorthand can only replace a complete 4-byte zero group. It must not appear in the middle of a 5-character group. Decoders should verify the current group is empty when encounteringz. -
Invalid Character Detection: Encoded characters must be in the ASCII 33–117 range (plus the optional
z). Decoders should validate each character. -
Delimiter Handling: Decoders should correctly identify and strip
<~ ~>delimiters, while also supporting input without delimiters. -
Large File Processing: For large files, use streaming (processing one 4-byte group at a time) to avoid loading the entire file into memory.
Advantages and Disadvantages
Advantages
- High Encoding Efficiency: 25% overhead — second only to Base91 among common encodings
- Zero Compression: Further reduces size for data with many null bytes
- Industry Standard: Widely adopted by Adobe PostScript/PDF and Git
- Fixed Ratio: The 4:5 encoding ratio makes output length easy to predict
- Delimiters:
<~ ~>provides clear boundary markers for extracting encoded data from mixed content
Disadvantages
- Contains Special Characters: Output includes characters like
\,",'that require escaping in many programming languages - Not URL Safe: Contains URL-special characters like
<,>,?,& - Case Sensitive: May cause issues in case-insensitive environments
- Implementation Complexity: More complex than Base64 (pure bit operations), requires division
- Multiple Variants: Ascii85, Z85, btoa, and others have different alphabets and are not interchangeable
Security Considerations
-
Base85 is not encryption: Like all encoding schemes, Base85 is merely a data representation and provides no confidentiality. Sensitive data must be encrypted before encoding.
-
Injection risks: Since Base85 output contains characters like
<,>, and", embedding it directly in HTML, XML, or SQL may lead to injection attacks. Proper escaping is required in these contexts. -
Data integrity: Standard Ascii85 includes no built-in checksum. If data integrity is required, add CRC or hash verification at the application level.
How to Choose the Right Encoding?
- Need maximum encoding efficiency with special chars allowed: Choose Base85 or Base91
- Need universal compatibility and broad support: Choose Base64 (RFC standard, native support in nearly all languages)
- Need URL safety: Choose Base62 or Base58
- Need to embed in PostScript/PDF: Choose Base85 (Ascii85)
- Need human-friendly, error-resistant input: Choose Base58 (no ambiguous characters)
Conclusion
Base85 (Ascii85) is a highly efficient and mature binary-to-text encoding scheme. With just 25% overhead, it significantly outperforms Base64 in encoding efficiency while offering practical features like z zero compression and <~ ~> delimiters. From Adobe PostScript/PDF to Git binary patches, Base85 plays an important role wherever compact text representation of binary data is needed.
If you’re working with PDF generation, Git patch parsing, or any scenario requiring efficient binary-to-text encoding, Base85 is an excellent choice. Try our Base85 Encoder/Decoder to experience it firsthand!