Luhn Checker
Validate whether a number passes the Luhn checksum used by payment cards.
How Luhn works
The Luhn algorithm doubles every second digit from the right, subtracts 9 from results above 9, sums all digits and checks divisibility by 10. It catches single-digit errors and most transpositions.
Related tools
Luhn steps diagram
How this tool works
The Luhn algorithm, also called mod 10, is a checksum defined in ISO/IEC 7812 and used by every major card network. It works on the digits of a card number from the right, doubling every second digit, subtracting 9 from any doubled result above 9, and summing everything. A number is valid if the final sum is a multiple of 10. The check digit itself takes part in the calculation, which is what lets it catch an error in itself.
It is a checksum, not a check of the account. The algorithm is arithmetic over the digits and contacts nothing: it cannot tell you whether a card exists, is active, has funds or has been reported. Its value is narrower and still very real. Single-digit errors, the most common kind of mistake when a number is typed, are caught every time, and so are transpositions of two adjacent digits, which is the second most common. A number that fails the check is almost certainly a typing mistake, and a number that passes is at least internally consistent.
Worked example
| Step | Value |
|---|---|
| Number | 4242 4242 4242 4242 |
| Digits doubled from the right | 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 |
| Doubled value, 9 subtracted above 9 | 8 4 8 4 8 4 8 4 8 4 8 4 8 4 8 4 |
| Sum | 72 |
| Result | 72 is a multiple of 10, so the number is valid |
This is the standard test number published for development use. It passes the checksum by construction, which is why it is safe to use in a test suite.
When to use it
- Catch a transcription error before a number reaches a payment form
- Validate a number that arrived from a scanner, an OCR pass or a CSV import
- Reject obviously malformed input at the edge of your system, cheaply and offline
- Check test card numbers in development without contacting anybody
- Teach the checksum itself, which is the standard example of a mod 10 code
Frequently asked questions
What is the Luhn algorithm?
A mod 10 checksum defined in ISO/IEC 7812 and used by every major card network. It doubles every second digit from the right, subtracts 9 from results above 9, sums the digits and checks that the total is a multiple of 10. The check digit is included in the calculation.
Does a valid Luhn check mean the card works?
No. It means the digits are internally consistent. Whether the account exists, is active or has funds can only be established by the issuer, and only through a transaction.
Which cards use the Luhn algorithm?
All the major brands: Visa, Mastercard, American Express, Discover, Union Pay, Diners Club and most national schemes. It is effectively universal for payment cards, which is why it is the default first check in any card number validator.
What errors does Luhn not catch?
It misses transpositions of two digits that are an odd distance apart, such as swapping the first and sixth digits, and it cannot catch a missing or extra digit. A single-digit error is always caught.
Why does the check digit take part in its own calculation?
So that an error in the check digit itself is caught. If it were computed over the other digits only, a mistyped check digit would go undetected in a large share of cases.
Is Luhn a security control?
No. It is an integrity control. It catches accidental errors, not deliberate edits, because anyone can compute a valid check digit for a number they have changed.
Should I reject a number that fails the check?
Yes, if the only source of the number is a human typing it. If it came from a data set, check whether the failure is a data quality problem in that set rather than a fraud signal, and log it either way.