The last digit that checks the rest
Card numbers, IMEI codes and many account identifiers end in a digit that is not part of the identifier at all. It is computed from the others so that a single mistyped character produces an invalid number rather than a valid one belonging to someone else.
The Luhn algorithm
Working right to left across the number, double every second digit. Where doubling gives a two-digit result, add the two digits together. Sum everything, then find the digit that brings the total to a multiple of ten.
Worked example: 7992739871
- Weighted sum: 67
- Next multiple of ten: 70
- Check digit: 70 − 67 = 3
- Complete number: 79927398713
What it catches, and what it misses
| Error type | Caught? |
|---|---|
| Any single mistyped digit | Always |
| Two adjacent digits swapped | Almost always |
| Swapping 0 and 9 when adjacent | No |
| Two separate digits both wrong | Sometimes |
Those two exceptions are the known limits of the algorithm. It was designed in 1954 to catch human transcription errors cheaply, not to resist deliberate forgery.
Where you meet it
Every payment card in circulation, IMEI numbers on mobile phones, Canadian social insurance numbers, and a large share of loyalty and account identifiers. It is also the reason a card form can tell you a number is wrong before contacting any bank.
That check happens in the browser, in a fraction of a second, and it removes the majority of typing errors before they reach a payment network.
It is not a security measure
Passing the Luhn check means a number is well formed. It says nothing about whether the account exists, has funds, or belongs to the person entering it.
Generating numbers that pass is trivial — the algorithm is public and this page performs it. Validation of an actual card requires the issuer, and no arithmetic on the number alone can substitute for it.
Card numbers carry more than the check digit
The first digit identifies the industry: 4 for Visa, 5 for Mastercard, 3 for travel and entertainment cards. The first six to eight digits are the issuer identification number, which routes the transaction to the right bank. The digits between that and the check digit are the account itself.
Other check digit schemes
Luhn is the most common but not the only one. ISBNs use a weighted modulo 11 that can produce a check character of X. IBANs use modulo 97 across the whole rearranged string, which catches more error types than Luhn at the cost of more computation.
Barcodes use modulo 10 with weights of 3 and 1 rather than doubling alternate digits. Each was chosen for the error profile of how its numbers get transcribed — spoken aloud, typed, or scanned.
Why the check happens before the network sees it
Validating in the browser costs nothing and rejects most typing errors instantly. Sending them to a payment network instead would cost a fee per attempt and slow the form down for everyone.
It also improves the error message. A form that says the number is invalid the moment you finish typing is more useful than one that waits, submits, and returns a generic decline that could mean a dozen different things.
Related calculators
- Percentage calculator — everyday arithmetic on any figure
- Credit card calculator — what the account behind the number costs
- Credit utilisation calculator — the ratio that affects your score