IBAN check digits: mod 97 step by step
Characters 3 and 4 of every IBAN are check digits. They are calculated from all the other characters so that the whole IBAN, read as one large number, leaves a remainder of 1 when divided by 97. A single wrong digit or two swapped neighbours break that. Below is the full calculation on GB82 WEST 1234 5698 7654 32, the test results from our own code, and the errors no check digit can catch.
The rule in one line
Move the first four characters to the end, replace each letter by a two-digit number (A = 10, B = 11 … Z = 35), and divide the result by 97. A valid IBAN always leaves remainder 1. That is the whole test. Everything else in this article is that line, done slowly.
Checking an IBAN, step by step
We use a British example that appears in many manuals and is valid:
- CountryGB
- Check digits82
- Bank codeWEST
- Sort code123456
- Account number98765432
Step 1: move the first four characters to the end
GB82 goes from the front to the back. The IBAN without spaces, rearranged, is WEST12345698765432GB82. Moving the country code and check digits to the end means the check digits are the last thing the division sees, which is what lets them be calculated.
Step 2: turn letters into numbers
Each letter becomes its position in the alphabet plus 9. Digits stay as they are.
| Letter | W | E | S | T | G | B |
|---|---|---|---|---|---|---|
| Number | 32 | 14 | 28 | 29 | 16 | 11 |
The string becomes one 28-digit number: 3214282912345698765432161182.
Step 3: divide by 97
That number is too large for a pocket calculator, and for many spreadsheets. The usual trick is to divide in pieces: take the first nine digits, find the remainder, put it in front of the next digits, and repeat. The final remainder is the same as dividing the whole number at once.
| Piece | Remainder after dividing by 97 |
|---|---|
| 321428291 | 70 |
| 70 + 2345698 = 702345698 | 29 |
| 29 + 7654321 = 297654321 | 24 |
| 24 + 61182 = 2461182 | 1 |
The remainder is 1. The IBAN passes. Our module computes the same remainder in one step, and the IBAN checker runs this test, along with country, length and structure, every time you type a character.
Calculating the check digits
To create the check digits instead of testing them, put 00 where they will go and run the same steps. For our example the national part is WEST 1234 5698 7654 32, so the rearranged string is WEST12345698765432GB00.
| Piece | Remainder after dividing by 97 |
|---|---|
| 321428291 | 70 |
| 70 + 2345698 = 702345698 | 29 |
| 29 + 7654321 = 297654321 | 24 |
| 24 + 61100 = 2461100 | 16 |
The remainder is 16. The check digits are 98 − 16 = 82. That is why the IBAN starts GB82. Subtracting from 98 is what makes the finished IBAN leave remainder 1 instead of 0.
The same calculation on other registry examples:
| National part with 00 | Remainder | 98 minus remainder | IBAN starts |
|---|---|---|---|
| GB: NWBK60161331926819 + GB00 | 69 | 29 | GB29 |
| DE: 370400440532013000 + DE00 | 9 | 89 | DE89 |
| IT: X0542811101000000123456 + IT00 | 38 | 60 | IT60 |
| FR: 20041010050500013M02606 + FR00 | 84 | 14 | FR14 |
A small remainder gives large check digits: the German remainder 9 gives 89. A remainder of 89 or more gives a single digit, which is written with a leading zero, so the IBAN still has two check digits. The IBAN calculator does all of this when you enter the national details.
Why check digits run from 02 to 98
A remainder lies between 0 and 96, so 98 minus it lies between 2 and 98. Real check digits are therefore never 00, 01 or 99. Those three values can still pass the remainder test, because adding or subtracting 97 does not change a remainder. Our checker rejects them anyway, with its own message, since no correctly calculated IBAN carries them.
Which errors the check digits catch
ISO 13616 promises that the check catches the common typing errors: one digit replaced by another, one letter replaced by another, two neighbouring digits swapped, and a character missing or added. A missing or extra character is in fact caught twice, because every country has a fixed length.
See it on our example. Change the last digit, so it ends in 33 instead of 32: the remainder becomes 28, not 1. Swap the last two digits, so it ends in 23: the remainder becomes 49. Drop the final 2: the IBAN has 21 characters instead of 22, and the length check fails before mod 97 is even reached.
We test this on every run. Our test suite takes the official example of each of the 89 countries and changes every character in turn, and swaps characters. Every error that ISO 13616 guarantees to catch was caught. Not one slipped through.
Which errors can slip through
Some countries allow letters and digits in the same field. Italy’s account part, France’s numéro de compte and the UK bank code are examples. An error that mixes the two, such as a digit typed for a letter, or a letter swapped with a digit, changes how many digits the number has after step 2. Then the mod 97 guarantee no longer holds. In theory about 1 in 97 of such errors can pass. In our tests these mixed errors were caught about 99.6 % of the time.
Two separate errors in one IBAN can also, by chance, cancel each other out. And the biggest gap is not a typing error at all: a correct IBAN for the wrong account passes every test. That is the scenario behind fake invoices, covered in is it safe to give out your IBAN.
National check digits: a second layer
Several countries kept their own check inside the national part, so their IBANs carry two independent checks. An error that slips past one is very likely caught by the other.
- Italy and San Marino: the CIN letter. In IT60 X054 2811 1010 0000 0123 456 it is X. See the Italian IBAN page.
- France and Monaco: the clé RIB, the last two digits. In FR14 2004 1010 0505 0001 3M02 606 it is 06, calculated with the M replaced by a digit. See the French IBAN page.
- Spain: the two DC digits inside the 20-digit CCC.
- Belgium: the last two digits, the remainder of the first ten divided by 97.
- Portugal: the NIB has its own mod-97 check, which is why every Portuguese IBAN starts with PT50.
- Poland: the 8th digit of the bank code checks the first seven.
Our checker tests all of these. The UK and Germany have no national check position in the IBAN format, so for those the IBAN check digits are the only arithmetic check. The IBAN formats by country page shows which countries have one.
Doing it in code
Two practical points if you write your own check. First, do not convert the whole string to a normal floating-point number: 28 or more digits are beyond its precision, and you will get a wrong remainder without any error. Use the piece-by-piece method above, or a big-integer type. Second, clean the input first: remove spaces and turn lower-case letters into capitals, then check the country code and length before mod 97. A clear "this IBAN has 21 characters, it needs 22" helps a user more than "checksum failed".
If you only want the answer, paste the IBAN into the IBAN checker. For the meaning of the other parts, read what an IBAN is.
Questions people ask
What are the check digits in an IBAN?
Characters 3 and 4. They are calculated from all other characters so that the IBAN, rearranged and converted to digits, leaves remainder 1 when divided by 97.
Can a valid IBAN still be wrong?
Yes. The check catches typing errors, not wrong accounts. A correct IBAN of someone else’s account passes, and in rare cases a mixed letter-and-digit error does too.
Why do Portuguese IBANs always start with PT50?
The 21-digit NIB already leaves remainder 1 when divided by 97, so the IBAN check digits come out as 50 every time.