---
title: "Bech32"
description: "BIP173 bech32 with a prefix and 5-bit words and a BCH checksum. With m it's BIP350 bech32m for Taproot"
canonical_url: "https://encodings.agntn.dev/encodings/bech32"
---
# Bech32

> BIP173 bech32 with a prefix and 5-bit words and a BCH checksum. With m it's BIP350 bech32m for Taproot

<encoding-facts name="bech32">



</encoding-facts>

A human-readable prefix, a `1`, then 5-bit words and six characters of checksum. The checksum is a BCH code that catches any four wrong characters. Base58 never came close.

```ts
encode("bech32", "gm", { prefix: "test" });  // "test1vaks69jerm"
decode("bech32", "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4");
// bytes: the 20-byte program, details: { prefix: "bc", witnessVersion: 0 }
```

A valid segwit v0 address comes back as its witness program. Anything else comes back as the bytes its words carry. A Nostr `npub`, say, or a Cosmos account. Mixed case is an error. Over 90 characters too, unless you raise `limit`. Lightning invoice? Raise it.

[Checksums](https://encodings.agntn.dev/guide/checksums) has the long version, segwit rules included.

## Bech32m

Bech32 had one embarrassing flaw. End a string in `p`, add or drop `q` characters right before it, and the checksum still passed. BIP350 fixed it by changing one constant. That's bech32m, and `m: true` switches to it.

```ts
decode("bech32", "bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0", { m: true });
// bytes: 79be667e…16f81798, details: { prefix: "bc", witnessVersion: 1 }
```

Taproot addresses, `bc1p…`, are bech32m. Version 0 stays on plain bech32. Read a v0 address with `m` and it fails. Read a Taproot one without it? `checksum is bech32m's`. Annoying? It's exactly the point.


## Sitemap

See the full [sitemap](https://encodings.agntn.dev/sitemap.md) for all pages.
