Luhn algorithm (mod-10) checker
The Luhn algorithm is a simple checksum invented by Hans Peter Luhn and used to catch accidental typos in identification numbers — credit and debit cards, IMEI device serials, SIM ICCIDs, and many national IDs all carry a Luhn check digit. This tool tells you instantly whether a number passes, and also computes the check digit, which is handy for generating consistent test data.
How it works
Walking the digits right to left:
- Every second digit is doubled. If doubling gives a result over 9, subtract 9 (equivalent to adding the two digits).
- All the digits are summed.
- The number is valid when the total is a multiple of 10.
To find the check digit for a payload (a number without its final digit), the tool computes the Luhn sum as if a 0 were appended, then the answer is (10 − sum mod 10) mod 10.
Example
Check 4539 1488 0343 6467 (a Luhn-valid test card):
- Doubling every second digit from the right and reducing values over 9 produces a running total.
- That total is a multiple of 10 → passes the Luhn check.
Now take a payload 7992739871 with no check digit. The Luhn sum of 79927398710 leaves a remainder, and the tool reports the required check digit as 3, so 79927398713 would pass.
What Luhn protects (and doesn’t)
| Detects | Misses |
|---|---|
| Any single wrong digit | The 09 ↔ 90 transposition |
| Most adjacent transpositions | Whether the account is real |
| Most twin-digit errors | Whether the card is active |
Privacy: the entire calculation runs in your browser. Nothing you type is uploaded, logged, or stored. A pass means the number is internally consistent — never that it belongs to a real, active account.
Where the Luhn algorithm is used in practice
Hans Peter Luhn invented the algorithm at IBM in 1954, and it was quickly adopted by the fledgling card industry as a lightweight way to catch input errors before sending data to a remote host — a significant concern when network time was expensive. Today, the Luhn check digit appears in:
- Credit and debit card numbers (Visa, Mastercard, American Express, Discover, and most others)
- IMEI numbers (the 15-digit identifier for every mobile handset)
- SIM card ICCIDs (19 or 20 digits identifying a SIM)
- Canadian Social Insurance Numbers
- Some national identity numbers and ISIN securities identifiers
The common thread is that these are long numbers prone to transcription errors, and the Luhn check catches the vast majority of single-digit mistakes before any database lookup is attempted.
What the algorithm does and does not guarantee
The Luhn check is deliberately lightweight. It detects all single-digit errors (typing a 3 where a 7 should be) and the majority of transposition errors (swapping two adjacent digits). It misses the swap of 09 and 90 because both produce the same doubled value. It has a roughly 1-in-10 chance of letting a completely random number pass — meaning that if you generate a random 16-digit string, about 10% of them will pass the Luhn check purely by chance.
That is fine for its intended purpose: catching accidental human errors in data entry. It was never designed to prevent deliberate fraud. A would-be fraudster can trivially generate Luhn-valid numbers by appending the right check digit. Card networks add cryptographic authentication on top — the card’s CVV2, the chip’s EMV cryptogram — to handle intentional fraud.
Building valid test card numbers
When building payment forms, developers need numbers that pass front-end Luhn validation without hitting a real card network. The canonical approach is:
- Choose a brand prefix (e.g., 4 for Visa, 51–55 for Mastercard)
- Fill in arbitrary digits to reach one less than the target length
- Compute the Luhn check digit for the payload
- Append it
The result passes every Luhn-based validator but refers to no real account. Use these only for testing; treat them as public test data since they are trivially reproducible.