Base58Check Encoding
← Back to Cryptography I: Blockchain Security and Cryptographic Foundations
Introduction
Cryptographic data is fundamentally binary—sequences of bytes with values from 0 to 255. But humans don't work well with binary data. We mistype it, confuse similar characters, and struggle to verify it. Base58Check encoding solves this problem by converting binary data into human-friendly strings that are easier to read, type, and verify.
This chapter explores how XRPL uses Base58Check encoding to create readable addresses, why certain characters are excluded, and how checksums provide error detection.
The Problem with Raw Binary
###Consider an account ID in different formats:
Binary (20 bytes):
10001011 10001010 01101100 01010011 00111111 ...
Hexadecimal:
8B8A6C533F09CA0E5E00E7C32AA7EC323485ED3F
Base58Check:
rN7n7otQDd6FczFgLdlqtyMVrn3LNU8B4CProblems with hex:
Easy to mistype:
8B8Avs8B8BVisually similar characters:
0(zero) vsO(letter O)No error detection: One wrong character, wrong address
Not compact: 40 characters for 20 bytes
Base58Check solutions:
Excludes confusing characters
Includes checksum (detects errors)
More compact: 34 characters for 20 bytes + checksum
URL-safe (no special characters)
The Base58 Alphabet
Excluded characters:
These exclusions prevent human transcription errors.
Included: 58 characters
Base58 Encoding Algorithm
Base58 is like converting a number to a different base (like hexadecimal is base 16):
The Mathematics
Handling Leading Zeros
This ensures the encoding is one-to-one: every distinct byte sequence produces a distinct string.
Implementation
Base58Check: Adding Error Detection
Base58 alone doesn't detect errors. Base58Check adds a checksum:
Encoding Process
Token Types
The type byte determines the first character of the encoded result:
This provides visual identification of what kind of data you're looking at.
Decoding and Validation
Error Detection
The 4-byte (32-bit) checksum provides strong error detection:
Types of errors detected:
Single character typos: 100%
Transpositions: 100%
Missing characters: 100%
Extra characters: 100%
Random corruption: 99.9999999767%
Complete Example: Account Address
Seeds and Human Readability
Seeds can be encoded in two formats:
Base58Check Format
Properties:
Compact (25-28 characters)
Checksum for error detection
Safe to copy-paste
RFC 1751 Word Format
Properties:
12 words from a dictionary
Easier to write down by hand
Easier to read aloud (for backup)
Checksum built into last word
Practical Usage
Creating an Account
Validating User Input
Parsing Different Token Types
Comparison with Other Encodings
Hex
16
No
No
No (2×)
Yes
Base64
64
Yes
No
Yes (1.33×)
No (+, /)
Base58
58
Yes
No
Yes (1.37×)
Yes
Base58Check
58
Yes
Yes (4 bytes)
Yes (1.37×)
Yes
Base58Check wins for:
Human readability (no confusing characters)
Error detection (checksum)
URL safety (no special characters)
Blockchain addresses
Common Pitfalls
❌ Typos Without Validation
Solution:
❌ Assuming All Addresses Start with 'r'
Solution:
❌ Manual Base58 Implementation
Solution:
Performance Considerations
When performance matters:
Summary
Base58Check encoding makes binary cryptographic data human-friendly:
Excludes confusing characters: No 0, O, I, l
Includes checksum: 4-byte SHA-256(SHA-256(...)) checksum
Type prefixes: Different first characters for different data types
Error detection: ~99.9999999767% of errors detected
URL-safe: No special characters
Compact: ~37% overhead vs 100% for hex
Usage in XRPL:
Account addresses: starts with 'r'
Seeds: starts with 's'
Public keys: starts with 'a' or 'n'
Best practices:
Always validate before using
Use library functions, don't implement yourself
Store binary internally, encode only for display
Provide clear error messages for invalid input
In the next chapter, we'll explore how cryptography secures peer-to-peer communication in the XRPL network.
Last updated

