Bitcoin Bech32 BIP173: SegWit v0 Addresses, HRPs, and Error Detection
Bech32 is the human-readable encoding specified by BIP173 for native SegWit addresses. It differs from Base58Check in alphabet, checksum design, and the way network and witness information are represented. Bech32 remains the correct checksum variant for SegWit witness version 0; it is not the checksum variant for Taproot.
Anatomy of a Bech32 address
A SegWit address begins with a human-readable part (HRP), followed by the separator 1, a data section, and a six-character checksum. Bitcoin mainnet uses bc as the HRP, testnet uses tb, and regtest uses bcrt. The data begins with the witness version encoded as a five-bit value, followed by the witness program converted from eight-bit bytes into five-bit groups.
For witness version 0, a 20-byte program corresponds to pay-to-witness-public-key-hash (P2WPKH), while a 32-byte program corresponds to pay-to-witness-script-hash (P2WSH). A wallet must validate both the address checksum and the version-specific program length. An address that passes generic Bech32 decoding may still fail SegWit address rules.
Why bit conversion matters
Bech32's data alphabet represents values from 0 to 31, not arbitrary bytes. Conversion between 8-bit witness-program bytes and 5-bit symbols must handle padding correctly. For address decoding, excess or nonzero padding is invalid. Accepting noncanonical padding can cause multiple strings to represent the same underlying program or lead to inconsistent validation across implementations.
BIP173's checksum is designed to detect common transcription errors and supports locating some errors. A Bech32 string must not mix upper- and lowercase letters. An all-uppercase string can be valid, but applications generally display lowercase to minimize confusion. The checksum protects against accidental corruption; it cannot certify that a payee supplied the intended destination.
Scope and migration
Bech32's original checksum has a weakness for certain insertion/deletion patterns involving the final character. BIP350 introduced Bech32m for witness versions 1 through 16, leaving witness version 0 on the original Bech32 checksum. Consequently, changing every bc1 address to Bech32m would break valid v0 payments.
For production validation, identify the network, decode the HRP and checksum, extract the witness version and program, then enforce the matching checksum variant and program-length rules. A prefix alone is not proof that an address is valid.
Primary references
BIP173 — Base32 address format for native v0-16 witness outputs: https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki
BIP350 — Bech32m format for v1+ witness addresses: https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki
