# Bech32m

> How a Pearl address is encoded: 5-bit groups, the bech32 alphabet and a 6-character BCH checksum. Every step worked through on a real address.

Source: https://pearlcodex.com/technical/keys/bech32m/ · Last updated: 2026-10-20 · Checked against Pearl's source code at v1.5.5

[Bech32m](https://pearlcodex.com/glossary/#bech32m) is the format every Pearl address is written in. It turns bytes into short, case-insensitive text and adds a checksum strong enough that a typo almost never gets through.

You don’t need to know any of this to use Pearl. But if you’ve ever wondered how a wallet can tell, instantly and offline, that you mistyped one character out of 63, this page computes it by hand.

## Try it

Decode an address, then break it. Change any single character and watch the checksum fail.

_Interactive: Bech32m explorer. Try it on the page: <https://pearlcodex.com/technical/keys/bech32m/>_

## What is the alphabet?

Bech32 uses 32 characters, one for each 5-bit value from 0 to 31:

| Value     | 0      | 1      | 2      | 3      | 4      | 5      | 6      | 7      | 8      | 9      | 10     | 11     | 12     | 13     | 14     | 15     |
| --------- | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ | ------ |
| **Char**  | q      | p      | z      | r      | y      | 9      | x      | 8      | g      | f      | 2      | t      | v      | d      | w      | 0      |
| **Value** | **16** | **17** | **18** | **19** | **20** | **21** | **22** | **23** | **24** | **25** | **26** | **27** | **28** | **29** | **30** | **31** |
| **Char**  | s      | 3      | j      | n      | 5      | 4      | k      | h      | c      | e      | 6      | m      | u      | a      | 7      | l      |

The order looks random on purpose. It was chosen so that characters people confuse (in handwriting and in common fonts) differ by as few bits as possible, which the checksum then catches best. The digit 1 and the letters b, i and o are left out entirely.

That’s why the version character of a Taproot address is p: p is 1 in this table. P2MR addresses use z, which is 2.

## How is an address encoded?

Here is every step for the address of private key 1. (A public, unsafe key: don’t send coins to it.) Its 32-byte program is the tweaked key Q:

`da4710964f7852695de2da025290e24af6d8c281de5a0b902b7135fd9fd74d21`

1. **Write the program as bits**

   `da 47 10 96…` becomes `11011010 01000111 00010000 10010110 …`, 256 bits in all.

2. **Regroup into fives**

   `11011 01001 00011 10001 00001 …` gives 27, 9, 3, 17, 1, … 256 bits make 51 full groups plus 1 leftover bit, which is padded with four zeros: 52 values.

3. **Put the version in front**

   Witness version 1 goes first: 1, 27, 9, 3, 17, … (53 values).

4. **Expand the prefix**

   Each letter of “prl” is split into its top 3 bits and bottom 5 bits, with a 0 between the halves: p = 112, r = 114, l = 108 give `3 3 3 0 16 18 12`.

5. **Run the polymod**

   Feed the expanded prefix, the 53 values and six zeros through the BCH polymod (below). Result: `0x199b14b2`.

6. **XOR with the bech32m constant**

   `0x199b14b2` XOR `0x2bc830a3` = `0x32532411`.

7. **Split into six checksum values**

   `0x32532411` as six 5-bit numbers: 25, 5, 6, 9, 0, 17.

8. **Write everything as characters**

   prefix `prl`, separator `1`, version `p`, program `mfr3p9j00pfxjh0zmgp99y8zftmd3s5pmedqhyptwy6lm87hf5ss`, checksum `e9xfq3`.

Result: `prl1pmfr3p9j00pfxjh0zmgp99y8zftmd3s5pmedqhyptwy6lm87hf5sse9xfq3`, 63 characters.

**All 59 data values of this address**

Version, then 52 program values, then 6 checksum values:

```text
p=1
m=27 f=9  r=3  3=17 p=1  9=5  j=18 0=15 0=15 p=1  f=9  x=6  j=18
h=23 0=15 z=2  m=27 g=8  p=1  9=5  9=5  y=4  8=7  z=2  f=9  t=11
m=27 d=13 3=17 s=16 5=20 p=1  m=27 e=25 d=13 q=0  h=23 y=4  p=1
t=11 w=14 y=4  6=26 l=31 m=27 8=7  7=30 h=23 f=9  5=20 s=16 s=16
e=25 9=5  x=6  f=9  q=0  3=17
```

The last program value, 16 (`s`), is `10000`: the final bit of the 32 bytes, a 1, followed by four zero bits of padding. A decoder checks that the padding is zero.

## How is an address checked?

The receiving wallet runs the same polymod over the expanded prefix and all 59 data characters, checksum included. A valid bech32m string always gives exactly the constant:

| Address                                          | Polymod result | Verdict                           |
| ------------------------------------------------ | -------------- | --------------------------------- |
| `prl1pmfr3…hf5sse9xfq3`                          | `0x2bc830a3`   | valid bech32m                     |
| `prl1pmfr3…hf5sse9xfq4` (last character changed) | `0x2bc830a7`   | **invalid**                       |
| `prl1pmfr3…hf5ssvek99n` (bech32 checksum)        | `0x00000001`   | valid _bech32_, rejected by Pearl |

The wallet never needs to know what the address “should” be. The checksum is self-checking, which is what lets a wallet refuse a typo before any coins move.

**Make a guess:** Could a single typo ever turn one valid Pearl address into another valid Pearl address?

**Answer:** No.

Bech32’s code is guaranteed to detect any error affecting up to 4 characters (BIP-173). Changing one character always breaks the checksum. Only a large, unlucky scramble has any chance of passing, and that chance is below one in a billion.

## How does the polymod work?

It’s the remainder of a polynomial division, done with shifts and XORs. Each 5-bit value is a coefficient of a polynomial over a small finite field, and the checksum is the remainder after dividing by a fixed generator polynomial. In code it’s ten lines:

```js
const GEN = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];

function polymod(values) {
  let chk = 1;
  for (const v of values) {
    const top = chk >>> 25;                          // the 5 bits about to fall off
    chk = (((chk & 0x1ffffff) << 5) ^ v) >>> 0;      // shift in the next value
    for (let i = 0; i < 5; i++) if ((top >>> i) & 1) chk = (chk ^ GEN[i]) >>> 0;
  }
  return chk;
}
// polymod([3,3,3,0,16,18,12, 1,27,9,3,17, …, 25,5,6,9,0,17]) === 0x2bc830a3
```

The five GEN numbers encode the generator polynomial. They come straight from BIP-173 and are unchanged in Pearl.

## Why bech32m and not bech32?

Bech32 (BIP-173) ended its checksum by XORing with 1. That turned out to have a flaw: if an address ended in p, you could insert or delete q characters just before it without breaking the checksum. Bech32m (BIP-350) fixes it by using the constant `0x2bc830a3` instead. Everything else is identical.

Bitcoin kept bech32 for its version-0 addresses (`bc1q…`) and uses bech32m for version 1 and up. Pearl has no version-0 addresses, so it accepts bech32m only.

> **Pearl vs Bitcoin**
>
> Same alphabet, same polymod, same constant. The only differences are the prefix (`prl` instead of `bc`) and the rule: Pearl’s decoder refuses a bech32 checksum outright (“expected bech32m encoding for witness version 1”), even for an address whose program and version are fine.

## What else does bech32m allow?

- **All capitals.** `PRL1PMFR3P9J00…HF5SSE9XFQ3` is valid; QR codes encode capitals more compactly. Mixed case is invalid.
- **Up to 90 characters.** The generic format allows long strings, but every Pearl address is exactly 63 (mainnet) or 64 (test networks) characters, because every Pearl program is 32 bytes.
- **No error correction in practice.** The code could, in theory, locate a small error. Wallets deliberately don’t “fix” addresses: a correction could produce a different valid address. They reject and ask you to copy it again.

## In short

- Bech32m writes bytes as characters from a 32-letter alphabet, five bits per character, and adds a 6-character checksum.
- The checksum is a BCH code: a polynomial remainder over the expanded prefix and all the data, XORed with the constant 0x2bc830a3.
- To check an address, run the same polymod over everything: a valid address gives exactly 0x2bc830a3.
- Any error in up to 4 characters is guaranteed to be caught; bigger errors slip through less than once in a billion tries.
- Pearl accepts bech32m only. An address with Bitcoin’s older bech32 checksum is rejected even if everything else is right.

## Read the code

- [Pearl always encodes with bech32m](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/btcutil/address.go#L17-L50) `node/btcutil/address.go:17-50`
- [Decoding rejects non-bech32m checksums](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/btcutil/address.go#L139-L175) `node/btcutil/address.go:139-175`
- [The bech32m constant 0x2bc830a3](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/btcutil/bech32/version.go#L14) `node/btcutil/bech32/version.go:14`
- [The generic 90-character limit (irrelevant for 63-character Pearl addresses)](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/btcutil/bech32/bech32.go#L292-L296) `node/btcutil/bech32/bech32.go:292-296`

## Sources

### Bitcoin standards

- [BIP-350: Bech32m format for v1+ witness addresses](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki)
- [BIP-173: Base32 address format (bech32)](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki)

### Other

- [learnmeabitcoin: Bech32](https://learnmeabitcoin.com/technical/keys/bech32/)
