GUIDE

What a check digit can tell you: IBANs, card numbers and other codes

How the Luhn and IBAN mod-97 checks work, with worked examples, which typing mistakes they catch or miss, and why a number that passes may not exist.

By StillKit · Published

A check digit is an extra digit, pair of digits or letter, calculated from the rest of a number with a fixed public formula. When you enter the number, a form or checker repeats the calculation, and a mismatch means a typing mistake. A number that passes is only consistent with its own formula. That says nothing about whether a bank, card issuer or government ever issued it.

The Luhn check behind card numbers

Card numbers end in a Luhn check digit. To test one, start from the rightmost digit and keep every first, third and fifth digit as it is, while doubling every second one. A doubled digit above 9 loses 9, so a doubled 8 counts as 16 − 9 = 7. Add everything up. The number passes when the total ends in 0.

Take the test card number 4111 1111 1111 1111. Counting from the right, the eight digits you keep are all 1s, which add up to 8. Seven of the doubled digits are 1s, worth 2 each, or 14. The last doubled digit is the leading 4, worth 8. The total is 8 + 14 + 8 = 30, which ends in 0, so the number passes. Change the final 1 to a 2 and the total becomes 31. The credit card number checker then reports "Fails the card number check."

The checker accepts 12 to 19 digits and ignores spaces and hyphens. It also names the likely network from the first digits, such as Visa for numbers starting with 4, which is a reading of the prefix, not a lookup. The same Luhn formula protects phone IMEI numbers, which the IMEI number checker tests at exactly 15 digits, and Canadian Social Insurance Numbers.

The mod-97 check behind IBANs

An international bank account number carries two check digits right after the country code. Here is the test, step by step, with the widely used example GB82 WEST 1234 5698 7654 32:

  1. Remove the spaces: GB82WEST12345698765432.
  2. Move the first four characters to the end: WEST12345698765432GB82.
  3. Replace each letter with a number, from A = 10 to Z = 35. Here W = 32, E = 14, S = 28, T = 29, G = 16 and B = 11, giving 3214282912345698765432161182.
  4. Divide that 28-digit number by 97. The IBAN is valid when the remainder is 1.

A pocket calculator cannot hold 28 digits, so work in pieces. Dividing 321428291 by 97 leaves 70. Put 70 in front of the next seven digits: 702345698 leaves 29. Then 297654321 leaves 24, and finally 2461182 leaves 1. The remainder is 1, so the check digits are right.

The check digits themselves come from the same sum. The bank writes 00 in their place, finds a remainder of 16, and subtracts it from 98, which gives 82. The IBAN validator runs this calculation, compares the length with its list of country lengths (22 characters for GB) and prints the result in groups of four.

Which mistakes each check catches and misses

The Luhn check catches every single wrong digit, and every swap of two neighboring digits except 09 written as 90 or the reverse. It misses "twin" errors, where a doubled pair turns into another doubled pair: 22 and 55, 33 and 66, and 44 and 77. When two digits are wrong at once, about 1 in 9 such mistakes passes anyway.

The mod-97 check is stronger. It catches every wrong digit, every letter replaced by another letter and every swap of two neighboring digits. Numbers with two random mistakes still pass about 1 time in 100. One gap is specific to StillKit's validator. It checks each country's length but not its pattern of letters and digits, so a letter typed where only digits belong also gets past roughly once in a hundred tries.

Other check digits in StillKit's checkers
NumberMethodTypical miss
EAN, UPC and ISBN-13 barcodesWeights 3 and 1, mod 10Swapped neighbors that differ by 5, such as 3 and 8
ISBN-10Weights 10 down to 2, mod 11, with X for 10None for a single wrong digit or any swap of two digits
Vehicle VINLetter values and weights, mod 11Letters that share a value, such as A and J

The barcode check digit checker tells you which digit should come last when a barcode number fails, and the ISBN validator and converter also turns a valid ISBN-10 into its ISBN-13 and back.

A number that passes may still not exist

The formulas are public, so anyone can invent a number and give it a correct check digit. About 1 in 10 random 16-digit numbers passes the Luhn check by pure chance. The test card number above passes, yet it is a test number, not a customer's card. The SIN checker's own example, 046 454 286, passes too, and the tool points out that SINs starting with 0 appear only in examples.

A passing check means "probably typed correctly". Only the issuer can confirm that a number is real, active and belongs to the person you are dealing with. That is the bank for an IBAN or a card, and the tax office for a tax number.

Some codes have no public check to run at all. A UK National Insurance number has no check digit, so its checker tests the format only, and India's PAN does have a check letter, but its method is not published. The VIN check digit is required in North America, while many vehicles from elsewhere do not use one. A failing VIN check on such a car is not proof of a typing mistake; the VIN decoder and check digit tool says so in its result.

Before you send money to a new IBAN:

  1. Paste it into the IBAN validator rather than retyping it. Spaces, dots and hyphens are ignored, and lowercase letters are accepted.
  2. If it fails, compare it with the original, character by character, looking for swapped neighbors and for O written as 0 or I written as 1.
  3. If it passes, still use your bank's own payee checks where it offers them, because only the bank knows whose account it is.
TRY IT YOURSELF

Tools used in this guide

Find your next shortcut

Search loads only when needed. Your search stays on your device.

Browse all categories and sections →