What this calculator does
The Luhn algorithm is the checksum behind credit card numbers, and it is designed to catch the errors people actually make: a mistyped digit, or two adjacent digits swapped.
The doubling step is what catches transpositions. Every second digit from the right is doubled, with 9 subtracted if the result exceeds 9, and a valid number has a digit total divisible by 10.
The formula
Working from the rightmost digit, every second digit is doubled and reduced by 9 if it exceeds 9. All digits are summed, and a total divisible by 10 indicates validity.
| Term | Meaning |
|---|---|
| Checksum | A digit computed from the others to detect errors. |
| Check digit | The final digit, chosen to make the total come out right. |
| Transposition error | Swapping two adjacent digits, which the algorithm catches in most cases. |
The inputs explained
| Field | What to enter |
|---|---|
| Digits (spaces allowed) | The digits to check or extend. Spaces and other non-digit characters are ignored. |
| Mode | Whether to validate the sequence as given, or compute a check digit to append. |
When to use it
Validating a card number
A failed Luhn check catches a typo before any network request is made.
Generating test data
Valid-looking test numbers need a correct check digit.
Understanding how checksums work
Luhn is the most widely encountered example.
Worked examples
Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.
What happens when one digit changes?
The same number with its last digit altered.
| Sequence | Valid by the Luhn check? | Digit sum (mod 10) |
|---|---|---|
| 4539 1488 0343 6467 | Yes | 0 |
| 4539 1488 0343 6468 | No | 1 |
Questions
What errors does Luhn catch?
All single-digit errors, and most transpositions of adjacent digits. The notable exception is swapping 09 for 90, which the doubling step happens not to detect.
Is Luhn a security measure?
Not at all. It is an error-detection check, and the algorithm is completely public. Generating a number that passes is trivial, which is why passing the check proves only that the digits were typed correctly.
Where else is it used?
Beyond payment cards, it appears in IMEI numbers for mobile phones, some national identification numbers, and various product codes. Any context wanting a cheap typo check is a candidate.
Why double every second digit?
Because it makes the checksum position-sensitive. Without doubling, swapping two digits would leave the sum unchanged and the error would pass undetected, which is precisely the failure the algorithm exists to prevent.
For modular arithmetic generally, see the modular exponentiation calculator. For digit-based checks, see the digital root calculator.