Base58Check Encoding
Base58Check Encoding (Legacy Addresses)
While nodes process the 20-byte hash directly, humans need a more readable format. Bitcoin uses Base58Check to create the iconic legacy addresses that start with the number 1.
1. Why Base58?
Standard Base64 includes characters that look very similar, such as 0 (Zero) and O (Capital O), or I (Capital I) and l (Lowercase L).
-
Base58 removes these ambiguous characters to prevent transcription errors.
-
It also removes
+and/so that addresses can be double-clicked and copied easily.
2. The Encoding Process
To turn a 20-byte Public Key Hash into an address, Bitcoin software follows these steps:
-
Add Version Byte: Prepend
0x00(Mainnet) to the hash. -
Double Hash: Calculate the
SHA256(SHA256(Result)). -
Checksum: Take the first 4 bytes of that hash.
-
Append Checksum: Add those 4 bytes to the end of the versioned hash.
-
Base58 Encode: Convert the final 25-byte string into the Base58 alphabet.
3. Error Detection
Because of the 4-byte checksum, if you mistype a single character in a legacy address, your wallet will recognize that the checksum doesn't match and will refuse to send the payment. This prevents coins from being sent into a "black hole" due to a typo.
4. Identifying P2PKH Addresses
-
Prefix: Because the version byte is
0x00, the Base58 encoding almost always results in a string starting with1. -
Length: Usually 34 characters (can vary between 26 and 35).
| Address Type | Version Byte | Starting Character | Encoding |
|---|---|---|---|
| Mainnet P2PKH | 0x00 |
1 |
Base58Check |
| Testnet P2PKH | 0x6f |
m or n |
Base58Check |
| Mainnet P2SH | 0x05 |
3 |
Base58Check |
In the final section, we will build a Python P2PKH Auditor.
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: