Base58 Arithmetic
Base58 Arithmetic
Converting a hexadecimal number to Base58 is not a simple character swap. It is a full-scale mathematical transformation. To understand how it works, we must treat the entire public key hash as one giant integer.
1. Treat Bytes as a Big Number
A Bitcoin address is usually 25 bytes of data (1 version + 20 hash + 4 checksum).
-
In decimal, this number is unimaginably large.
-
To convert this to Base58, we perform a process called Successive Modulo Division.
2. The Algorithm
-
Take the giant number ($N$).
-
Divide $N$ by 58.
-
The Remainder (0 to 57) corresponds to a character in the Base58 alphabet. This becomes the last character of the address.
-
The Quotient becomes the new $N$.
-
Repeat until the Quotient is zero.
3. Reverse Order
Because we are finding the remainders from right to left, the characters are generated in reverse order. The first division gives you the very last character of the address.
4. Why Base 58?
The number 58 was chosen because it is roughly $2^6$ (which is 64).
-
It is small enough to be efficient for division on 2009-era hardware.
-
It is large enough to keep the address strings short.
5. Calculation Example
Imagine we are encoding the number 1000 into a custom Base58:
-
$1000 \div 58 = 17$ (Quotient), Remainder 14.
-
Character 14 in the alphabet is
F. -
$17 \div 58 = 0$ (Quotient), Remainder 17.
-
Character 17 in the alphabet is
J. -
Result: JF.
| Step | Operation | Resulting Char |
|---|---|---|
| 1 | Large Number % 58 | Char at index R |
| 2 | Large Number // 58 | New Number |
| 3 | Repeat | Build string backwards |
In the next section, we will discuss the special handling of Leading Zeroes.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: