Bech32 Math (BCH Codes)
Bech32 Math: BCH Codes
While legacy addresses use hashing, modern SegWit addresses (bc1...) use a completely different mathematical approach called BCH (Bose-Chaudhuri-Hocquenghem) Codes. This method is similar to the technology used in QR codes and CDs to ensure data can be read even if it is slightly damaged.
1. Polynomial Division
Bech32 checksums are not hashes. Instead, they are the Remainder of a polynomial division.
-
The data in the address is treated as a series of coefficients in a mathematical equation.
-
This equation is divided by a specific "Generator Polynomial."
-
The result (the remainder) is the 6-character checksum at the end of the address.
2. Why is this better than Hashing?
Hashing is "Chaotic." If you change one character, the hash changes completely. This tells you that there is an error, but it doesn't tell you where.
-
Error Localization: Because BCH codes are based on algebra, they can detect the specific position of typos.
-
Guaranteed Detection: Bech32 is mathematically guaranteed to detect up to 4 character errors in a single address. It is also optimized to detect "Transpositions" (e.g., typing
12instead of21), which are common human mistakes.
3. The 6-Character Length
Bech32 uses a 6-character checksum (30 bits of data).
- Even though it uses fewer bits than Base58 (30 bits vs. 32 bits), the Algebraic Structure makes it significantly more robust against the specific types of errors humans make.
4. The Checksum Constant
In Bech32m (Taproot), the math is identical, but the final remainder is XOR'd with a different constant.
-
Bech32: XOR with
1. -
Bech32m: XOR with
0x2be89091. This small change ensures that a wallet won't accidentally treat a Taproot address as a SegWit v0 address.
| Feature | Base58 (Hash) | Bech32 (BCH) |
|---|---|---|
| Math | SHA256 Hashing | Polynomial Division |
| Error Location | Impossible | Possible |
| Transposition Check | Random | Mathematical Guarantee |
| Implementation | Simple | Complex |
In the next section, we will analyze the Probability of Failure.
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: