TeachMeBitcoin

Base58Check Encoding

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

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).

2. The Encoding Process

To turn a 20-byte Public Key Hash into an address, Bitcoin software follows these steps:

  1. Add Version Byte: Prepend 0x00 (Mainnet) to the hash.

  2. Double Hash: Calculate the SHA256(SHA256(Result)).

  3. Checksum: Take the first 4 bytes of that hash.

  4. Append Checksum: Add those 4 bytes to the end of the versioned hash.

  5. 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

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.

☕ Help support TeachMeBitcoin

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:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!