The Luhn check digit, explained
The Luhn algorithm is a simple checksum that catches most typing mistakes in long identification numbers. IBM scientist Hans Peter Luhn patented it in 1960, and today it guards payment card numbers, IMEI numbers of mobile phones, Canadian social insurance numbers and many loyalty and account numbers. The last digit of such a number is a check digit chosen so that the whole number passes the test.
This tool checks whether a number passes and calculates the check digit to append to a number that does not have one yet. It is useful for testing payment forms and validating data imports.
How to use it
- Type or paste the number. Spaces and dashes are ignored, so you can paste card numbers as printed.
- Read whether the number is valid and the checksum the tool computed.
- To make a number valid, enter it without its last digit and read the check digit to append.
- Use Append check digit to copy the complete, valid number.
Example: a standard test card number and a check digit
4539 1488 0343 6467 7992739871 (needs a check digit)
Valid, checksum 80 79927398713
The checksum must be a multiple of 10. For 7992739871 the right check digit is 3, the textbook example from the algorithm's description.
How the algorithm works
Start from the rightmost digit and move left. Double every second digit; if doubling gives a number above 9, subtract 9 (or add its two digits). Then add up all the digits. If the total ends in 0, the number is valid. To create a check digit, run the same steps on the number with a placeholder at the end and pick the digit that brings the total to the next multiple of 10.
What it catches and what it does not
The Luhn check detects every single mistyped digit and almost every swap of two neighbouring digits; the one swap it misses is 09 and 90. It does not catch every double error, and it was never meant as security. Anyone can compute a valid check digit, as this page shows, so passing Luhn only means a number is well formed, not that a card or account exists.
Testing payment forms
Payment providers publish test card numbers that pass Luhn but never charge money, for example in Stripe's and Adyen's documentation, and those are the right numbers for testing checkout flows. Do not generate numbers to try against real merchants: real cards also need a valid expiry date and security code, and probing with made-up numbers is fraud.
Questions
Does this tool store or send card numbers?
No. The check runs in your browser and nothing is saved or sent. Still, avoid typing real card numbers into websites you do not need to.
Is a Luhn-valid number a real card?
No. About one in ten random numbers passes the check. Only the card issuer can say whether a number is a real account.
Do all card types use Luhn?
Visa, Mastercard, American Express, Discover and most other major networks do. The first digits identify the network and issuer, and the last digit is the Luhn check digit.