Base58: Encoding built for Humans

Base58 is an encoding standard that makes it easy to represent binary data as readable strings. At its core, it’s designed to convert bits (binary zeros and ones) into characters that are safe for both humans and machine parsing.

For example this byte array in binary 00000100 10101110 11111111 in decimal represents 306175 and by repeatedly dividing by 58 and recording the remainders and using the Base58 alphabeth we get the base58 encoded version 2a1Y.

306175 ÷ 58 = 5278, remainder 31Base58 character 'Y'
5278 ÷ 58 = 91, remainder 0Base58 character '1'
91 ÷ 58 = 1, remainder 33Base58 character 'a'
1 ÷ 58 = 0, remainder 1Base58 character '2'

Base58 alphabeth:

DecimalBase58 CharacterDecimalBase58 CharacterDecimalBase58 Character
0120M40h
1221N41i
2322P42j
3423Q43k
4524R44m
5625S45n
6726T46o
7827U47p
8928V48q
9A29W49r
10B30X50s
11C31Y51t
12D32Z52u
13E33a53v
14F34b54w
15G35c55x
16H36d56y
17J37e57z
18K38f
19L39g

There’s an interesting detail in its design that sets it apart from other encoding schemes. It excludes the digit “0”, uppercase “O”, uppercase “I”, and lowercase “l.” Why? These characters are visually similar and can easily be confused. By leaving them out, Base58 ensures that people won’t mistake “0” for “O” or “I” for “l” when reading or comparing the encoded values.

Another advantage of Base58 is its single, stable alphabet that is compatible with URLs and Filenames. Base64 for example has multiple alphabets as detailed in RFC 4648 to target these use-cases and this alone can cause bugs and confusion.

However, this design choice does come with a trade-off. Base58 requires around 25% more characters to represent the same amount of data compared to Base64.

Update: As Paul Miller highlighted in his tweet, Base58 has a complexity upper bound of O(n^2), making it impractical for processing data larger than 1KB due to potential crashes.

Published at: 2024-11-07
Updated at: 2024-11-07


Join the Newsletter

Thoughts on Software Engineering with a focus on React, Cryptography, CRDTs and Effect.