Encodings

Bech32

Checksummed Base32 address encodings for Bitcoin SegWit and Taproot (BIP-173, BIP-350)

standard Safe API Not cryptographic

About Bech32

Bech32 is one of 2 Bech32 and Bech32m variants in the NextSSL registry, a binary-to-text encoding. It takes the parameter hrp. Its registry entry cites BIP-173. NextSSL lists it in the standard tier and exposes it through the safe API.

Overview

Bech32 is a Base32-based encoding with a strong BCH error-detecting checksum, introduced in BIP-173 for Bitcoin SegWit addresses. Bech32m, defined in BIP-350, fixes a weakness in the original checksum and is used for Taproot addresses. Neither provides any security against deliberate tampering.

A Bech32 string has a human-readable prefix such as 'bc', a '1' separator, a data part in a 32-character lowercase alphabet chosen to avoid confusable characters, and a 6-character checksum. The checksum is a BCH code over GF(32) that guarantees detection of up to four character errors and has a very low probability of missing other errors. Bech32m changes only the constant XORed into the checksum.

The original Bech32 checksum has a flaw: inserting or deleting 'q' characters before a final 'p' can leave the checksum valid. Bech32m was introduced to address this for new address versions. NextSSL includes both. Bech32 strings are case-insensitive but must not mix cases. Both encode a witness version and program for Bitcoin addresses, with Bech32 used for version 0 and Bech32m for versions 1 and above.

History

2017–2017
  1. Bech32 and Bech32m published by Pieter Wuille, Greg Maxwell

Security notes

Bech32 and Bech32m detect accidental errors but are not cryptographic; an attacker can produce any valid string. They provide no confidentiality or authenticity.

Typical uses

Bitcoin SegWit (Bech32) and Taproot (Bech32m) addressesLightning invoices and other human-typed identifiers

Sizes

The registry declares no fixed sizes for this algorithm.

Parameters

NameTypeRangeDefaultRequired
hrp str 1 – 83 — yes

Parameters are passed as a string, for example nextssl_mac("hmac", "hash=sha512", …). Omitted parameters take their declared default.

Use it

from nextssl_demo import NextSSL

ns = NextSSL()              # safe API: safe and standard tiers
text = ns.call("encode_with", "bech32", None, b"hello")[0]
data = ns.call("decode_with", "bech32", None, text)[0]

Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.

Other Bech32 and Bech32m variants

1

Frequently asked questions

What is Bech32?

Bech32 is an encoding in the Bech32 and Bech32m family. Bech32 is a Base32-based encoding with a strong BCH error-detecting checksum, introduced in BIP-173 for Bitcoin SegWit addresses.

Who designed Bech32 and when?

Bech32 belongs to the Bech32 and Bech32m family, first published in 2017 by Pieter Wuille, Greg Maxwell. Its origin: BIP-173; BIP-350.

Which standards define Bech32?

Bech32 is referenced by BIP-173.

Is Bech32 safe to use?

Bech32 is in the standard tier. Standardised and sound. Reachable from the safe API. It can be called from the safe API.

What other Bech32 and Bech32m variants are there?

NextSSL also registers bech32m in the Bech32 and Bech32m family.