← Cryptography guide

K105 / Encoding and decoding

Bech32

Bech32 encoding BIP 173 · Survey date 2026-12-05

Bech32 is an encoding format consisting of a human-readable part (HRP), the separator '1', and a data part.

CRYPTOGRAPHY LAB / K105

Cryptography Lab · Bech32

Run real computations and inspect intermediate states step by step.

Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.

Scope: Limited implementation

Bech32 / Bech32m (raw data, not address validator)

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Reference ↗

Open lab →

Definition and overview
Bech32 is an encoding format consisting of a human-readable part (HRP), the separator '1', and a data part. Source document ↗
Classification and reversibility
Bech32/Bech32m are reversible encodings supporting encoding and decoding. Source document ↗
Key or secret requirements
Keyless encoding, not encryption. Source document ↗
Operating principle and structure
Treats data as GF(32) polynomial coefficients for checksum computation. Source document ↗
Key size, block size and parameters
BIP173 limits strings to 90 characters. Source document ↗
Security strength and recommendation
BIP350 specifies Bech32m for witness version 1 and later. Source document ↗
Known attacks and vulnerabilities
Reference C decoder had a buffer overflow caused by unsigned integer overflow. Source document ↗
Standards and certification
Specified by BIP173/BIP350 (Bech32m). Source document ↗
Typical uses
Bitcoin SegWit and Taproot (v1+) addresses. Source document ↗
Implementations, libraries and tools
BIP173/BIP350-compatible libraries such as bitcoinjs/bech32. Source document ↗
Decryption or decoding
Decoding returns HRP and data without checksum. Source document ↗
Advantages
Human-readable and efficient for QR encoding. Source document ↗
Limitations and cautions
BIP173 has a 90-character limit. Source document ↗
Distinguishing encryption, encoding and hashing
Not encryption; uses an alphabet different from RFC 4648 Base32. Source document ↗

Practical examples

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

Example

Convert data bytes to five-bit words and append HRP, separator and checksum to create a Bech32 string. Decode by validating HRP/checksum and restoring bytes. No actual secret is used.

Procedure

Encode bytes as five-bit words, calculate checksum from HRP and data, form HRP+'1'+data+checksum. Decode by checking length, case and separator, validating HRP/checksum and restoring eight-bit bytes. Public keyless conversion, not encryption/decryption.

Scenario

Bitcoin wallets display SegWit addresses or transfer them via QR. Decode received addresses and validate HRP, version and witness program; for v1+ verify Bech32m.

Pitfalls and alternatives

Do not mix Bech32 and Bech32m; match witness version. Not standard Base32 or encryption. Check 90-character limits, malformed input and downgrade risks; validate HRP/checksum using vetted libraries.

References