Skip to content
BIP ATLAS

BIP 0173 + 0350

How does an address notice a typing mistake?

The last six characters of a bc1 address form a checksum. They help detect typing errors but add no destination data. A decoder checks the checksum and the address format before accepting the address.

Copy an address by hand and sooner or later you will get a character wrong. Older Bitcoin addresses made that easy. They mix upper- and lowercase letters, which are awkward to write down, type on a phone or read aloud. Their checksum also gave no guarantee about which mistakes it would catch.1

The bc1 format separates an address’s contents from a short checksum. A decoder checks both before accepting the string. Bech32 and Bech32m have the same overall shape, with different checksum rules for different witness versions.2345

Source revision
bitcoin/bips @ 3a10b5b
Source checked
1 October 2026
Review state
Awaiting review
Source details

This chapter is an independent explanation, not the proposal itself. Preamble fields are shown as the pinned files record them, without author e-mail addresses. Status is the proposal’s own field. It is not an endorsement or a sign of consensus.

BIP 173: Base32 address format for native v0-16 witness outputs

BIP
173
Layer
Applications
Title
Base32 address format for native v0-16 witness outputs
Authors
Pieter Wuille
Greg Maxwell
Comments-Summary
No comments yet.
Comments-URI
https://github.com/bitcoin/bips/wiki/Comments:BIP-0173
Status
Deployed
Type
Informational
Assigned
2017-03-20
License
BSD-2-Clause
Replaces
142
Proposed-Replacement
350

Pinned source · Reader view on bips.dev
SHA-256 b19eab06b264bbd15ad7f7d640fa34de8f4a8809fba8a6ecc3e165545b27a543
Git blob 5bcc4a5255bc85c78f3a4abaa7f4782f8acf6477

BIP 350: Bech32m format for v1+ witness addresses

BIP
350
Layer
Applications
Title
Bech32m format for v1+ witness addresses
Authors
Pieter Wuille
Status
Deployed
Type
Specification
Assigned
2020-12-16
License
BSD-2-Clause
Replaces
173

Pinned source · Reader view on bips.dev
SHA-256 63634b06aa8bae88b31929674736e74964c4598684269ac2b0b140c43a7a0dec
Git blob 8acc839867639c780621dc11aa401b0b181d69cb

Fig. A04.1 Anatomy of a SegWit address

Anatomy of a SegWit addressbc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4: prefix, network: mainnet: bc; separator, always 1: 1; version, witness v0: q; program, 20 bytes · 32 characters: w508d6qejxtdg4y5r3zarvary0c5xw7k; checksum, bech32 · no information: v8f3t4.bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4PREFIXNETWORK: MAINNETSEPARATORALWAYS 1VERSIONWITNESS V0PROGRAM20 BYTES · 32 CHARACTERSCHECKSUMBECH32 · NO INFORMATION
Anatomy of a SegWit addressbc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4: prefix, network: mainnet: bc; separator, always 1: 1; version, witness v0: q; program, 20 bytes · 32 characters: w508d6qejxtdg4y5r3zarvary0c5xw7k; checksum, bech32 · no information: v8f3t4.bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4PREFIXNETWORK: MAINNETSEPARATORALWAYS 1VERSIONWITNESS V0PROGRAM20 BYTES · 32 CHARACTERSCHECKSUMBECH32 · NO INFORMATION
Forty-two characters, five jobs. Only the version and the program describe the destination. The prefix names the network, the 1 marks where data begins, and the last six characters exist only to be checked.23678

Four parts and an alphabet

Read the example from BIP 173 left to right. First comes a human-readable prefix, bc, which names the network: mainnet. Testnet uses tb. Then comes a separator, which is always the digit 1. Everything after it is the data part. If a prefix ever contained a 1 of its own, the last 1 in the string would be the separator.268

The data part is written in an alphabet of exactly 32 characters: lowercase letters and digits, minus 1, b, i and o. BIP 173 chose the set, and even the order of its characters, using data about which characters people confuse with one another.9

Fig. A04.2 Thirty-two characters

Thirty-two charactersThe 32 data characters in value order, 0 to 31: q = 0, p = 1, z = 2, r = 3, y = 4, 9 = 5, x = 6, 8 = 7, g = 8, f = 9, 2 = 10, t = 11, v = 12, d = 13, w = 14, 0 = 15, s = 16, 3 = 17, j = 18, n = 19, 5 = 20, 4 = 21, k = 22, h = 23, c = 24, e = 25, 6 = 26, m = 27, u = 28, a = 29, 7 = 30, l = 31. Of the 36 lowercase letters and digits, 1, b, i, o are left out.32 CHARACTERS · ONE PER 5-BIT VALUEq0p1z2r3y495x687g8f9210t11v12d13w14015s16317j18n19520421k22h23c24e25626m27u28a29730l31LEFT OUT:1bioNO CASE: ONE ADDRESS, TWO SPELLINGS (ALL LOWER, ALL UPPER)
The data alphabet, each character with the 5-bit value it stands for. Digit 1 and the letters b, i and o are left out.9

Because the alphabet has no case distinctions, an address can be written entirely in capitals. BIP 173 recommends exactly that inside QR codes, whose alphanumeric mode is considerably more compact. What a decoder must refuse is a string that mixes the two cases. The checksum is always computed on the lowercase form.10

Fig. A04.3 One case at a time

One case at a timebc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 and BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4 are the same address in lower and upper case; both decode to 0014751e76e8199196d454941c45d1b3a323f1433bd6. tb1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vq47Zagq mixes cases (an uppercase Z at position 59) and is refused at the first check.bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4✓ VALID · LOWERCASEBIP 173 LINE 64BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4✓ VALID · UPPERCASE, SAME SCRIPTBIP 173 LINE 306 · COMPACT IN QR CODES…3k2e72q4k9hcz7vq47Zagq✕ REFUSED AT CHARACTERS: MIXED CASEBIP 350 LINE 208
Exact strings
BIP 173 line 64
bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4
BIP 173 line 306
BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4
BIP 350 line 208
tb1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vq47Zagq
BIP 173’s example in lower and in upper case decodes to the same script. A BIP 350 vector with one capital letter among lowercase ones is refused before any other check.810

Six characters for error detection

The last six characters of the data part are the checksum. They add no information about the destination. A decoder uses them to check the preceding characters. Most possible strings fail this check, which helps the decoder detect typing errors.3

The decoder converts each data character to a number from 0 to 31. It places numbers derived from the prefix before these values. It then passes the sequence to a function that BIP 173 calls polymod. A correctly encoded Bech32 string produces exactly 1. Any other result means the Bech32 checksum is invalid.11

Fig. A04.4 Checking the six characters

  1. Checking the six characters, step 1 of 4The data part qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 becomes the values 0, 14, 20, 15, 7, 13, 26, 0, 25, 18, 6, 11, 13, 8, 21, 4, 20, 3, 17, 2, 29, 3, 12, 29, 3, 4, 15, 24, 20, 6, 14, 30, 22, 12, 7, 9, 17, 11, 21.qw508d6q…0142015713260…39 VALUES · THE LAST 6 ARE THE CHECKSUM

    Each of the 39 data characters becomes its value, 0 to 31.

  2. Checking the six characters, step 2 of 4The prefix bc has character codes 98, 99. Expanded, it is 3, 3, 0, 2, 3: each code divided by 32, then 0, then each code modulo 32.b = 98c = 9933023CODE ÷ 32CODE MOD 32THE PREFIX IS CHECKSUMMED TOO

    The prefix “bc” goes in too: the high bits of each letter, a 0, then the low bits.

  3. Checking the six characters, step 3 of 4The 5 prefix values and the 39 data values, 44 in all, go through polymod.5 + 39 = 44 VALUES · LAST 6 = CHECKSUMPOLYMOD

    All 44 values run through polymod, a fixed function that keeps a 30-bit state.

  4. Checking the six characters, step 4 of 4polymod returns 0x00000001, which equals the Bech32 constant, so the checksum is valid.RESULT0x00000001= BECH32 ✓THE ENCODER CHOSE THE 6 CHECKSUMVALUES TO LAND EXACTLY HERE

    The result is exactly 1, the Bech32 constant. Any other result: the string is not one an encoder produced.

BIP 173’s example, checked step by step. The prefix and every data character feed one function, and a correctly copied Bech32 string gives exactly 1.811
Details: what polymod does

The function implements a BCH code. It keeps a 30-bit state, six characters of five bits each, and folds in one fixed generator value for every bit that overflows the top as each new character arrives. The prefix is fed in twice: first the high bits of each of its characters, then a zero, then the low bits, so that a typo in the prefix is caught too. When encoding, the six checksum values are chosen so that the final state equals the agreed constant.11

BIP 173 states that the code detects any error affecting at most four characters. It gives a less than one-in-a-billion chance of missing larger errors. BIP 350’s later analysis specifies character substitutions: each checksum detects up to four substituted characters when checked by its own verifier. Our reading is that a decoder supporting both families cannot apply this guarantee to edits that also change the witness version. An edit can change the witness version and thus the required checksum family. BIP 350 describes the v1+-to-v0 case as unlikely but hard to analyze.121314

Choose the valid version 0 sample below and change a character in its data. Watch the checksum check fail, then restore the sample. The decoder notices the error; it does not choose a replacement address for you.8111516

Fig. A04.5 Checksum lab

Static view: Valid v0. With JavaScript you can switch samples and change any one character after the separator; the table after this figure lists every sample’s result either way.

Checksum labThe string bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4. Accepted: witness version 0, a 20-byte program, protected by Bech32 as that version requires.VALID V0 · 42 CHARACTERSbc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4PREFIXCHECKSUMPREFIXSEPARATORVERSIONPROGRAMCHECKSUMTHE DECODER’S CHECKS, IN ORDER01 CHARACTERS✓ PASSED02 STRUCTURE✓ PASSED03 CHECKSUM✓ PASSED04 NETWORK✓ PASSED05 PROGRAM✓ PASSED06 FAMILY✓ PASSEDCOMPARE CHECKSUM FAMILIESPOLYMODRESIDUE0x00000001BECH32 ✓0x00000001BECH32M0x2bc830a3DECODER RESULT · scriptPubKey00OP_014PUSH 20751e76e8199196d454941c45…PROGRAM · BECH32 CHECKED
Checksum labThe string bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4. Accepted: witness version 0, a 20-byte program, protected by Bech32 as that version requires.VALID V0 · 42 CHARACTERSbc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4PREFIXCHECKSUMPREFIXSEPARATORVERSIONPROGRAMCHECKSUMTHE DECODER’S CHECKS, IN ORDER01 CHARACTERS✓ PASSED02 STRUCTURE✓ PASSED03 CHECKSUM✓ PASSED04 NETWORK✓ PASSED05 PROGRAM✓ PASSED06 FAMILY✓ PASSEDCOMPARE CHECKSUM FAMILIESPOLYMODRESIDUE0x00000001BECH32 ✓0x00000001BECH32M0x2bc830a3DECODER RESULT · scriptPubKey00OP_014PUSH 20751e76e819…PROGRAM · BECH32 CHECKED

Accepted: witness version 0, a 20-byte program, protected by Bech32 as that version requires.

Exact values for this string
String
bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4
Polymod residue
0x00000001
Witness program
751e76e8199196d454941c45d1b3a323f1433bd6
scriptPubKey
0014751e76e8199196d454941c45d1b3a323f1433bd6

Sample: BIP 173, line 64 (Examples). Public test material; never send funds to it.

Any single change you make to a valid sample is stopped at the checksum stage. This decoder reports that the string is wrong, not where: the dark cell marks your edit, and the decoder is not told its position.581315161718
Every sample on this page, and where it stops
All results are computed at build time by the same tested decoder the lab uses. Every string is a public test vector copied from the pinned BIP text.815171819
Sample String Outcome Reason or result Source
Valid v0 bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 ✓ Accepted v0, 0014… (20-byte program) BIP 173 L64
Valid v1 bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0 ✓ Accepted v1, 5120… (32-byte program) BIP 350 L193
Wrong checksum family bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqh2y7hd ✕ Stopped at Family Version 1 requires Bech32m, but the checksum is Bech32. BIP 350 L198
One wrong character bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5 ✕ Stopped at Checksum Checksum mismatch: the residue matches neither constant. BIP 173 L316
v0 with a Bech32m checksum bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kemeawh ✕ Stopped at Family Version 0 requires Bech32, but the checksum is Bech32m. BIP 350 L201
BIP 173's own v1 example bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx ✕ Stopped at Family Version 1 requires Bech32m, but the checksum is Bech32. BIP 173 L308
Mixed case tb1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vq47Zagq ✕ Stopped at Characters Mixes uppercase and lowercase letters. BIP 350 L208
Letter outside the alphabet bc1p38j9r5y49hruaue7wxjce0updqjuyyx0kh56v8s25huc6995vvpql3jow4 ✕ Stopped at Structure “o” is not in the Bech32 alphabet. BIP 350 L203
Unknown prefix “tc” tc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vq5zuyut ✕ Stopped at Network Prefix “tc” is not the expected “tb”. BIP 350 L197
v0 program of the wrong length BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P ✕ Stopped at Program A version 0 program must be 20 or 32 bytes, not 16. BIP 350 L207
Too much padding bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v07qwwzcrf ✕ Stopped at Program More than 4 bits of padding. BIP 350 L209
Witness version above 16 BC130XLXVLHEMJA6C4DQV22UAPCTQUPFHLXM9H8Z3K2E72Q4K9HCZ7VQ7ZWS8R ✕ Stopped at Program Witness version 17 is above 16. BIP 350 L204

It notices; it does not repair

Look at what the checksum stage reports when you change a character: only that the result matches neither constant. Codes of this family can, in principle, locate a few errors and even correct them. BIP 173 advises implementations against the second part.1116

Automatic correction can produce a valid address for a different destination. This can happen when the number of errors exceeds what the code can correct. Sending funds to the resulting address can cause an irreversible loss. Implementations should at most indicate possible error locations. They should leave correction to the user, who can compare the address with its source.16

Fig. A04.6 A typo, caught and not repaired

  1. A typo, caught and not repaired, step 1 of 4bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 gives the polymod result 0x00000001, the Bech32 constant.bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4POLYMOD → 0x00000001= BECH32 CONSTANT ✓

    BIP 173’s example address, copied correctly: the checksum holds.

  2. A typo, caught and not repaired, step 2 of 4bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5, BIP 173's invalid-checksum vector, differs at position 42. Its polymod result is 0x00000000, which matches neither constant.bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5POLYMOD → 0x00000000MATCHES NEITHER CONSTANT ✕

    One character changed, at position 42: 4 became 5.

  3. A typo, caught and not repaired, step 3 of 4The decoder rejects the string at the checksum stage. It does not report which character is wrong.DECODERREJECTED AT THE CHECKSUMTHIS DECODER: NO POSITION, NO GUESS

    This decoder reports that the string is wrong, not where. BIP 173 allows at most a hint where an error might be.

  4. A typo, caught and not repaired, step 4 of 4BIP 173 advises against correcting beyond pointing to where an error might be: an incorrect but valid address can lose funds. The fix is to copy the address again.“DID YOU MEAN …?”NO AUTO-CORRECTION: A WRONG BUT VALIDADDRESS CAN LOSE FUNDS FOR GOOD

    It offers no corrected version. Copy the address again from its source.

BIP 173’s example and its published one-character typo. The checksum catches the change; the decoder reports no position and offers no fix.8111516
Caveat

A wallet that silently fixes an address is not being helpful. If an address is rejected, copy it again from its source rather than accepting a guess.16

Why there are two checksums

The firm guarantee covers substituted characters. A different kind of mistake turned out to slip through. When a Bech32 string ends in p, inserting or deleting any number of q characters just before that final p leaves the checksum valid.1320

Fig. A04.7 The q insertion

The q insertionSchematic: a Bech32 string whose last character is p. Inserting one q, or three, just before that p leaves the checksum valid; deleting q characters there does too. BIP 350 notes that version 0 addresses were not affected because they are restricted to two lengths, 42 or 62 characters; a few inserted q characters give a length version 0 does not allow.…······p✓A BECH32 STRING THAT ENDS IN p…······qp✓ONE q INSERTED: CHECKSUM STILL VALID…······qqqp✓THREE q INSERTED: CHECKSUM STILL VALIDSCHEMATIC · VERSION 0 ESCAPED: ONLY TWO LENGTHS,42 OR 62 · A FEW INSERTED q GIVE A LENGTH V0 FORBIDS
A schematic of the weakness BIP 350 describes: q characters inserted just before a final p leave a Bech32 checksum valid. Version 0 addresses escaped because only two lengths are allowed.2021

BIP 350 notes that existing version 0 addresses were not affected, because they are restricted to two lengths, 42 or 62 characters. It also warns that the weakness may affect future uses of the format.2122

The fix is deliberately small. Bech32m is Bech32 with one change: the constant a valid string must produce. Instead of 1, it is 0x2bc830a3. The alphabet, the separator, the prefixes and the polymod function all stay the same.4

One computation, two accepted results. The witness version decides which one is required.45
Witness versionChecksumRequired result
0Bech320x00000001
1 to 16Bech32m0x2bc830a3

Fig. A04.8 Two constants

Two constantsbc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4: residue 0x00000001, version 0, accepted. bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0: residue 0x2bc830a3, version 1, accepted. bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqh2y7hd: residue 0x00000001, refused: Version 1 requires Bech32m, but the checksum is Bech32.. Bech32's constant is 0x00000001, Bech32m's 0x2bc830a3.POLYMODONE FUNCTIONBECH32 · V00x00000001BECH32M · V1–V160x2bc830a3TWO ACCEPTED RESULTSbc1qw508d6qejxtdg4y5r3zarv…v8f3t40x00000001VERSION 0 + BECH32 ✓ ACCEPTEDbc1p0xlxvlhemja6c4dqv22uap…zk5jj00x2bc830a3VERSION 1 + BECH32M ✓ ACCEPTEDbc1p0xlxvlhemja6c4dqv22uap…h2y7hd0x00000001VERSION 1 + BECH32 ✕ REFUSED AT FAMILY
Exact strings
BIP 173 line 64
bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4
BIP 350 line 193
bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0
BIP 350 line 198
bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqh2y7hd
One function, two accepted results. The v1 program with a Bech32 checksum passes the checksum stage and is refused only when the version and the family are compared.4581718

A decoder therefore checks the result against both constants, then checks that the one it found is the one the version requires. That last step is not a formality. In the lab, choose Wrong checksum family. The string passes the checksum stage, because it is a perfectly valid Bech32 string, and is rejected only at the end, because its version is 1.517

No string can be valid under both constants. Even so, BIP 350 explains that a decoder accepting either one for version 0 would weaken its error detection to the equivalent of a 29-bit checksum. The version and the checksum have to agree.2324

Bech32m deliberately requires updated software. Software that only knows Bech32 rejects every Bech32m address. BIP 350 argues that this incompatibility protects older senders from the insertion weakness. It also protects against implementations that experiments had shown would burn funds sent to version 1 addresses. At the time, the BIP noted that no wallets were creating version 1 addresses yet.2526

Details: BIP 173's own examples, revisited

BIP 173 listed Bech32 addresses for versions 1, 2 and 16 among its valid test vectors. Under BIP 350 those exact strings are invalid, and BIP 350 lists the same programs with Bech32m checksums. The tests behind this page check both lists against the pinned text, and the table above shows where one of BIP 173's examples now stops.519

What the characters carry

Between the separator and the checksum sit the actual contents. The first data character is the witness version, a number from 0 to 16 held in a single five-bit character. After it comes the witness program, between 2 and 40 bytes long.72728

Bytes have eight bits and characters carry five, so the program is regrouped. Write out its bits, cut them into groups of five and look each group up in the alphabet. A 20-byte program is 160 bits, exactly 32 characters. A 32-byte program is 256 bits, which takes 52 characters, the last one ending in four bits of zero padding. A decoder reverses the process and must reject padding that is longer than four bits or not all zeroes.2728

Fig. A04.9 Eight-bit bytes, five-bit characters

Eight-bit bytes, five-bit charactersstart of a 20-byte program (Valid v0): bytes 75 1e 76 e8 19, bits 0111010100011110011101101110100000011001, cut into 5-bit groups 01110 = 14 = w, 10100 = 20 = 5, 01111 = 15 = 0, 00111 = 7 = 8, 01101 = 13 = d, 11010 = 26 = 6, 00000 = 0 = q, 11001 = 25 = e: characters 5 to 12 of the address. end of a 32-byte program (Valid v1): bytes 17 98, bits 0001011110011000 plus 4 zero bits of padding, cut into 5-bit groups 00010 = 2 = z, 11110 = 30 = 7, 01100 = 12 = v, 00000 = 0 = q: characters 53 to 56 of the address.START OF A 20-BYTE PROGRAM · CHARACTERS 5–12751e76e81914w2051507813d2660q25eBLACK = 1 · BYTES ALIGN WITH CHARACTERS EVERY 40 BITSEND OF A 32-BYTE PROGRAM · CHARACTERS 53–5617982z30712v0qBLACK = 1 · DASHED: 4 ZERO BITS OF PADDING
Exact programs, in full
Valid v0 · 20 bytes
751e76e8199196d454941c45d1b3a323f1433bd6
Valid v1 · 32 bytes
79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
The same bits, cut two ways. Byte boundaries and character boundaries line up only every 40 bits. Half the characters in each complete 40-bit block therefore straddle two bytes, and a 32-byte program needs padding to fill its final character.8182728

Finally, the address becomes the script that a transaction output actually contains. The version becomes an opcode, OP_0 for version 0 and OP_1 to OP_16 for the rest, written as the byte 0x00 or the bytes 0x51 to 0x60. Then come the program's length and the program itself. BIP 173 warns that getting this mapping wrong is likely to produce an output that is unspendable or insecure. The lab shows the resulting script for each valid sample.81829

Fig. A04.10 From address to script

From address to scriptbc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4: version character q is 0, written as the opcode byte 00; then 14, a push of 20 bytes; then the program 751e76e8199196d454941c45d1b3a323f1433bd6. bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0: version character p is 1, written as the opcode byte 51; then 20, a push of 32 bytes; then the program 79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798.q00014751e76e8199196…VERSIONOP_0PUSH 20PROGRAMp1512079be667ef9dcbb…VERSIONOP_1PUSH 32PROGRAMOP_0 = 0x00 · OP_1 … OP_16 = 0x51 … 0x60
Exact scripts
Valid v0
0014751e76e8199196d454941c45d1b3a323f1433bd6
Valid v1
512079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
The version character becomes an opcode, then come the program’s length and the program: the scripts for BIP 173’s v0 example and BIP 350’s v1 vector.81829

What a valid address does not tell you

Passing every stage in the lab means one thing: the string is a well-formed SegWit address. It does not say who controls it, whether it has ever been used, or whether sending to it is wise.30

Version numbers make this concrete. The format accepts every version from 0 to 16. BIP 350 asks senders to recognise all of them as valid recipients, so that future upgrades work with existing wallets. The same paragraph says versions not defined on the network should never be created or handed to a sender.31

What a program means comes from other BIPs. BIP 141 gives version 0 programs of 20 and 32 bytes their meaning, and BIP 341 defines a Taproot output as version 1 with a 32-byte program. A version 1 address with a program of any other length can be valid as an address and still not be a Taproot output.3233

Note

Every address on this page is a public test vector copied from the BIP text. None of them should ever receive funds.818

The six characters, again

The six checksum characters let software detect errors without adding destination data. Each checksum always detects up to four character substitutions when a string is checked against its own family’s checksum. Other changes have probabilistic guarantees, with the cross-family limits described above. Implementations should reject invalid addresses, indicate possible error locations at most, and leave correction to the user.312131416

Bech32m changed a single constant to close a gap that the original guarantee never covered. It also tied each witness version to the checksum that must protect it.4520

How the address formats changed

Addresses that begin with bc1 were designed the other way round. BIP 173, assigned in 2017, defined their format, Bech32. BIP 350, assigned in 2020, amended it with a variant called Bech32m. Together they say what every character means and what a decoder must do when one of them is wrong.34

The checksum helps a wallet catch a copying mistake. It cannot establish who controls the destination or decide what you meant to type. A valid encoding is the start of interpreting an address.1630

Evidence

Each numbered marker in the text points here, and the ↩ links lead back to the text. Quotes are verbatim from the BIP files at commit 3a10b5b, wiki markup included. Links open the exact lines. Labels say what kind of statement each entry is: a rule, the author’s rationale, history, a test vector, or our own inference.

  1. ↩ Author’s rationale BIP173 motivates a new format partly because base58's mixed case is hard to write down, type, or read aloud, and its double-SHA256 checksum has no error-detection guarantees.

    Quoted source text (2)

    The mixed case in base58 makes it inconvenient to reliably write down, type on mobile keyboards, or read out loud.

    BIP 173, line 37

    The double SHA256 checksum is slow and has no error-detection guarantees.

    BIP 173, line 38
  2. ↩ a b c Rule A Bech32 string is at most 90 characters: a human-readable part, the separator "1" (the last 1 in the string), and a data part of at least 6 characters.

    Quoted source text (3)

    string is at most 90 characters long and consists of:

    BIP 173, line 79

    the last one in the string is the separator

    BIP 173, line 81

    The '''data part''', which is at least 6 characters long

    BIP 173, line 89
  3. ↩ a b c d Rule The last six characters of the data part are the checksum and carry no information of their own.

    Quoted source text (1)

    The last six characters of the data part form a checksum and contain no information.

    BIP 173, lines 127–128
  4. ↩ a b c d e Rule Bech32m changes only the final constant xored into the checksum, from 1 to 0x2bc830a3; all other aspects of Bech32 are unchanged.

    Quoted source text (2)

    replacing the constant ''1'' that is xored into the checksum at the end with ''0x2bc830a3''

    BIP 350, line 38

    All other aspects of Bech32 remain unchanged, including its human-readable parts (HRPs).

    BIP 350, line 65
  5. ↩ a b c d e f g Rule Witness version 0 is encoded with Bech32; versions 1 and higher with Bech32m; the decoder must check that the encoding matches the decoded version.

    Quoted source text (2)

    If its witness version is 0, encode it using Bech32. * If its witness version is 1 or higher, encode it using Bech32m.

    BIP 350, lines 92–93

    the address decoder has to verify that the encoding matches what is expected for the decoded witness version

    BIP 350, line 95
  6. ↩ a b Rule A SegWit address uses the human-readable part bc for mainnet and tb for testnet, and decoders must check it.

    Quoted source text (1)

    MUST verify that the human-readable part is "bc" for mainnet and "tb" for testnet.

    BIP 173, line 221
  7. ↩ a b Rule The first data character holds the witness version as 5 bits, and decoders must check that it is between 0 and 16.

    Quoted source text (2)

    1 character (representing 5 bits of data): the witness version

    BIP 173, line 212

    MUST verify that the first decoded data value (the witness version) is between 0 and 16, inclusive.

    BIP 173, line 222
  8. ↩ a b c d e f g h i j k l m Test vector Public example: bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 is the mainnet P2WPKH example; its uppercase form decodes to scriptPubKey 0014751e76e8199196d454941c45d1b3a323f1433bd6.

    Quoted source text (3)

    Mainnet P2WPKH: <tt>bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4</tt>

    BIP 173, line 64

    <tt>BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4</tt>: <tt>0014751e76e8199196d454941c45d1b3a323f1433bd6</tt>

    BIP 350, line 186

    <tt>BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4</tt>: <tt>0014751e76e8199196d454941c45d1b3a323f1433bd6</tt>

    BIP 173, line 306
  9. ↩ a b Rule The data part uses 32 alphanumeric characters, excluding 1, b, i and o; the set and its order were chosen using visual-similarity data.

    Quoted source text (2)

    only consists of alphanumeric characters excluding "1", "b", "i", and "o"

    BIP 173, line 89

    The character set is chosen to minimize ambiguity according to

    BIP 173, lines 90–91
  10. ↩ a b Rule Checksums are computed on the lowercase form; decoders must reject mixed case; uppercase is recommended inside QR codes.

    Quoted source text (5)

    The lowercase form is used when determining a character's value for checksum purposes.

    BIP 173, line 186

    Decoders MUST NOT accept strings where some characters are uppercase and some are lowercase

    BIP 173, line 192

    inside QR codes uppercase SHOULD be used

    BIP 173, line 194

    which is 45% more compact than the normal

    BIP 173, line 195

    <tt>tb1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vq47Zagq</tt>: Mixed case

    BIP 350, line 208
  11. ↩ a b c d e f Rule Verification expands the human-readable part (high bits, a zero, low bits), appends the data values, runs the polymod function, and compares the result with a constant: 1 for Bech32. The encoder picks the six checksum values so the result lands on that constant; the code is a BCH code.

    Quoted source text (5)

    return [ord(x) >> 5 for x in s] + [0] + [ord(x) & 31 for x in s]

    BIP 173, line 146

    return bech32_polymod(bech32_hrp_expand(hrp) + data) == 1

    BIP 173, line 149

    This implements a [https://en.wikipedia.org/wiki/BCH_code BCH code] that

    BIP 173, line 152

    polymod = bech32_polymod(values + [0,0,0,0,0,0]) ^ 1

    BIP 173, line 168

    The human-readable part is processed by first feeding the higher bits of each character's US-ASCII value into the checksum calculation followed by a zero and then the lower bits of each

    BIP 173, lines 156–158
  12. ↩ a b Author’s rationale BIP173 states that its BCH code guarantees detection of any error affecting at most four characters, with under a 1 in 10^9 chance of missing larger errors.

    Quoted source text (2)

    guarantees detection of '''any error affecting at most 4 characters'''

    BIP 173, line 153

    has less than a 1 in 109 chance of failing to detect more errors.

    BIP 173, lines 154–155
  13. ↩ a b c d Author’s rationale BIP350's analysis restates the firm guarantee as substitutions: Bech32 always detects up to four substituted characters, and Bech32m keeps that property. Its detection table reports the result for each code checked by its own verifier (Bech32m/Bech32m and Bech32/Bech32: 100% of patterns of up to four substitutions have failure probability 0).

    Quoted source text (4)

    Bech32 has a probability of 0 to incorrectly accept error patterns consisting of up to 4 substitutions—they are always detected.

    BIP 350, line 224

    For Bech32m, we aim to retain Bech32's guarantees for substitution errors

    BIP 350, line 218

    | &leq; 4 || only subst. || any || rowspan="6" | Bech32m/Bech32m || 100.00%|| colspan="5" | none

    BIP 350, line 252

    | &leq; 4 || only subst. || any || rowspan="6" | Bech32/Bech32 || 100.00%|| colspan="5" | none

    BIP 350, line 264
  14. ↩ a b Editorial inference BIP350 reports detection properties separately for each code and verifier pair, and calls errors that change a witness version across checksum families unlikely but hard to analyze. Its four-substitution guarantee therefore applies within one checksum family, not to a decoder that accepts both.

    Quoted source text (3)

    Whether this line is about Bech32 or Bech32m encoded strings, and whether those are evaluated regarding their probability of being accepted by either a Bech32 or a Bech32m verifier.

    BIP 350, line 236

    This situation may in theory occur for segregated witness addresses when errors occur that change the version number in a v1+ address to v0. Due to the specificity of this type of error, plus the additional constraints that apply for v0 addresses, this is both unlikely and hard to analyze.

    BIP 350, line 236

    a valid Bech32 and Bech32m string will always differ by at least 3 characters if they are the same length.

    BIP 350, line 95
  15. ↩ a b c d Test vector Public test vector: the v0 example with its last character changed is an invalid checksum.

    Quoted source text (1)

    <tt>bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5</tt>: Invalid checksum

    BIP 173, line 316
  16. ↩ a b c d e f g h Rule Error correction erodes error detection; implementations should not correct beyond suggesting where an error might be, because an incorrect but valid input can lose funds irrecoverably.

    Quoted source text (3)

    Use of an incorrect but valid input can cause funds to be lost irrecoverably.

    BIP 173, lines 178–179

    implementations SHOULD NOT implement correction beyond potentially suggesting to the user where in the string an error might be found, without suggesting the correction to make.

    BIP 173, lines 179–182

    implementations should refrain from using this for more than indicating where an error may be present.

    BIP 350, line 123
  17. ↩ a b c d Test vector Public test vectors: the same v1 program with a Bech32 checksum, and the v0 example with a Bech32m checksum, are both invalid.

    Quoted source text (2)

    <tt>bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqh2y7hd</tt>: Invalid checksum (Bech32 instead of Bech32m)

    BIP 350, line 198

    <tt>bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kemeawh</tt>: Invalid checksum (Bech32m instead of Bech32)

    BIP 350, line 201
  18. ↩ a b c d e f g Test vector Public test vector: a v1 Bech32m address that decodes to a 32-byte program.

    Quoted source text (1)

    <tt>bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0</tt>: <tt>512079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798</tt>

    BIP 350, line 193
  19. ↩ a b History BIP173 listed Bech32 v1, v2 and v16 addresses as valid; BIP350 lists the same programs with Bech32m checksums instead.

    Quoted source text (2)

    <tt>bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx</tt>

    BIP 173, line 308

    <tt>bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y</tt>

    BIP 350, line 188
  20. ↩ a b c Rule Bech32 has an insertion weakness: when the final character is p, inserting or deleting q characters just before it leaves the checksum valid.

    Quoted source text (1)

    whenever the final character is a 'p', inserting or deleting any number of 'q' characters immediately preceding it does not invalidate the checksum.

    BIP 350, line 28
  21. ↩ a b Author’s rationale BIP350 states the weakness does not affect version 0 addresses, because they are restricted to two lengths. It may affect future uses.

    Quoted source text (2)

    This does not affect existing uses of witness version 0 BIP173 addresses due to their restriction to two specific lengths

    BIP 350, line 28

    but may affect future uses and/or other applications using the Bech32 encoding.

    BIP 350, line 28
  22. ↩ Rule BIP141 makes a version 0 program of any length other than 20 or 32 bytes fail; BIP173 asks decoders to enforce such known-length rules, so v0 addresses are always 42 or 62 characters.

    Quoted source text (2)

    If the version byte is 0, but the witness program is neither 20 nor 32 bytes, the script must fail.

    BIP 173, lines 229–230

    Version 0 witness addresses are always 42 or 62 characters

    BIP 173, line 233
  23. ↩ Rule No string is valid as both Bech32 and Bech32m; two valid strings of the same length, one of each kind, differ in at least three characters.

    Quoted source text (2)

    a valid Bech32 and Bech32m string will always differ by at least 3 characters if they are the same length.

    BIP 350, line 95

    No string can be simultaneously valid Bech32 and Bech32m

    BIP 350, line 164
  24. ↩ Author’s rationale Accepting both encodings for version 0 would weaken detection to the equivalent of a 29-bit checksum.

    Quoted source text (1)

    Permitting both encodings reduces the error detection capabilities (it makes it equivalent to only have 29 bits of checksum).

    BIP 350, line 88
  25. ↩ Author’s rationale BIP350 intentionally breaks forward compatibility: old Bech32-only senders reject Bech32m addresses, which the author argues protects them from the mutation issue and from burning funds.

    Quoted source text (3)

    the Bech32m proposal breaks forward-compatibility for sending to v1 and higher version segregated witness addresses

    BIP 350, line 135

    the chosen approach will prevent such software from destroying funds when attempting to send to a Bech32m address.

    BIP 350, line 135

    those experiments identified cases in which segregated witness implementations would have caused wallets to burn funds when sending to version 1 addresses.

    BIP 350, line 135
  26. ↩ History When BIP350 was written, it noted that no wallets were creating v1 addresses yet, because the output type was not usable on mainnet.

    Quoted source text (1)

    no wallets are creating v1 segregated witness addresses yet, as the output type is not usable on mainnet.

    BIP 350, line 133
  27. ↩ a b c Rule The 2-to-40-byte witness program is written as bits, regrouped into 5-bit groups padded with zeroes, and each group becomes one character.

    Quoted source text (2)

    A conversion of the 2-to-40-byte witness program

    BIP 173, line 213

    Re-arrange those bits into groups of 5, and pad with zeroes at the end if needed.

    BIP 173, line 215
  28. ↩ a b c Rule When decoding, an incomplete final group must be at most 4 bits and all zeroes, and there must be 2 to 40 bytes.

    Quoted source text (2)

    Any incomplete group at the end MUST be 4 bits or less, MUST be all zeroes, and is discarded.

    BIP 173, line 225

    There MUST be between 2 and 40 groups, which are interpreted as the bytes of the witness program.

    BIP 173, line 226
  29. ↩ a b Rule Converting to a scriptPubKey stores version n as OP_n: 0x00 for version 0 and 0x51–0x60 for versions 1–16; getting this wrong can make an output unspendable or insecure.

    Quoted source text (2)

    OP_0 is encoded as 0x00, but OP_1 through OP_16 are encoded as 0x51 though 0x60

    BIP 173, lines 236–238

    If a bech32 address is converted to an incorrect scriptPubKey the result will likely be either unspendable or insecure.

    BIP 173, lines 238–239
  30. ↩ a b Editorial inference Passing the address checks establishes encoding validity only; it does not establish ownership, use, or whether sending is wise.

    Quoted source text (2)

    Use of an incorrect but valid input can cause funds to be lost irrecoverably.

    BIP 173, lines 178–179

    no recipient should ever provide them to a sender

    BIP 350, line 151
  31. ↩ Rule BIP350 asks senders to treat all higher witness versions as valid recipients, while saying versions not defined on the network should never be created or handed to a sender.

    Quoted source text (3)

    All higher versions of native segregated witness outputs should be recognized as valid recipients.

    BIP 350, line 151

    As higher versions are not defined on the network, no wallet should ever create them and no recipient should ever provide them to a sender.

    BIP 350, line 151

    future soft forks introducing higher versions of native segwit outputs will be forward-compatible to all wallets correctly implementing the Bech32m specification.

    BIP 350, line 151
  32. ↩ Rule In BIP141, a 20-byte version 0 program must match the HASH160 of a public key, and a 32-byte one must match the SHA256 of a witness script.

    Quoted source text (2)

    The HASH160 of the public key must match the 20-byte witness program.

    BIP 141, line 97

    SHA256 of the <code>witnessScript</code> must match the 32-byte witness program.

    BIP 141, line 103
  33. ↩ Rule BIP341 defines a Taproot output as a native SegWit output with version 1 and a 32-byte witness program; the address format itself does not define that meaning.

    Quoted source text (1)

    A Taproot output is a native SegWit output (see [[bip-0141.mediawiki|BIP141]]) with version number 1, and a 32-byte witness program.

    BIP 341, line 58
  34. ↩ History BIP173 was assigned in 2017 and BIP350, which lists itself as replacing BIP173, in 2020. Both preambles record the status Deployed.

    Quoted source text (4)

    Assigned: 2017-03-20

    BIP 173, line 11

    Assigned: 2020-12-16

    BIP 350, line 8

    Replaces: 173

    BIP 350, line 11

    Status: Deployed

    BIP 350, line 6