algorithm · 2025-01-06 · 7 min read
What the Luhn algorithm actually checks (and what it doesn't)
A single formula from 1954 sits behind almost every card number. Here is exactly what it validates, why it catches typos, and why passing it proves nothing about a real account.

Every payment card number ends with a check digit. That digit is not random: it is computed from the other digits with a formula patented by Hans Peter Luhn at IBM. When you mistype a digit, the formula almost always fails, and a checkout form can tell you so before anything is sent to a bank. You can watch it happen live in our interactive Luhn lab.
The algorithm is sometimes called mod 10 because the final test is whether a sum is divisible by ten. It is public domain, deliberately simple, and appears in far more places than cards: phone IMEIs, Canadian social insurance numbers and many national IDs use it too.
The four steps, with an example
- Starting from the right-most digit, double every second digit.
- If a doubled value exceeds 9, subtract 9 (equivalent to summing its two digits: 16 → 1 + 6 = 7).
- Add all the resulting digits together.
- If the total is divisible by 10, the number passes.
Take Stripe's famous test number 4242 4242 4242 4242. Doubling every second digit from the right turns each 4 into 8, so the sum is 8 × 8 + 2 × 8 = 80, which is divisible by 10. Change the last digit to 3 and the sum becomes 81 — the number fails. Try exactly that in the inspection bench.
Why the check digit is derived from the number itself
The issuer picks the first 15 digits (the IIN plus the account identifier) and then computes the 16th so that the whole string passes. That is why the check digit can be verified offline with no network call — and also why it is not a secret.
What Luhn does not prove
Passing Luhn means the string is well-formed. It says nothing about whether an account exists, is active, is unblocked, or has funds.
Anyone can generate a number that passes — which is exactly how BIN attacks work and why real acceptance happens only inside an authorized payment gateway with 3-D Secure, CVV and address checks. Treat Luhn as a spell-checker for numbers, not as a lock.
Where it falls short
Luhn detects every single-digit error and most adjacent transpositions, but not all of them. The one classic blind spot is swapping 09 and 90; read the transposition Luhn cannot catch for the full picture, and see the external Wikipedia article for the formal description.

Keywords: Luhn algorithm, check digit, credit card validation, mod 10, card number checksum, Hans Peter Luhn
Frequently asked questions
Is a Luhn-valid number a real credit card?
No. Luhn only confirms the digits are internally consistent. Real cards must also exist at an issuer, be active, and pass authorization.
Which card brands use the Luhn algorithm?
Visa, Mastercard, American Express, Discover, JCB, Diners Club, UnionPay and Maestro all end their numbers with a Luhn check digit.
Can I validate a CVV with Luhn?
No. The security code is generated with issuer keys and cannot be computed from the card number.