(Some of) the math behind Bech32 addresses

Mathematical background

Finite fields


Base 32

Converting bits to characters and back

Base32 character conversion table from BIP 173

BCH codes

  • n, the size of the codeword block (the length of the data+checksum). For BIP-173 this was chosen to be 1023 = 32²-1. So the order of 32 modulo n is m=2.
  • d, the minimum distance between codewords. This was chosen to be 4 for the block size of 1023 in BIP-173 (meaning that up to 3 errors was guaranteed to be detected), but the exact generator polynomial (discussed below) was then picked to actually guarantee error detection of 4 errors in up to 89 characters.
  • c, which determines exactly which minimal polynomials (defined below) to use to determine the generator polynomial.

How PolyMod works


Creating a checksum

Verifying a checksum

Encoding and decoding

Cool/useful links




Cryptography (mathematics) PhD candidate | Software dev | https://github.com/meshcollider

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Lesson 8: How to Analyze Calculations

Algebraic Geometry For Neuroscience

An Introduction to Log Odds

Lessons from a Deeptech Startup: On Applying Mathematics

An introduction to Bayes’ theorem

G. H. Hardy — Rigorous & Shy

Factors & Prime Factorization

The Big Bang Theory-Sheldon Prime

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Samuel Dobson

Samuel Dobson

Cryptography (mathematics) PhD candidate | Software dev | https://github.com/meshcollider

More from Medium

Edward Bernays: The Godfather Of Social Engineering & Modern Propaganda

Summer Top Water Slammers!

5 Random Acts of Kindness

[Projects]To the Moon