Luhn Algorithm Calculator
Validate numbers with the Luhn mod 10 algorithm and compute check digits for credit cards, IMEI, and identification numbers with step-by-step math.
What is the Luhn Algorithm (Mod 10)?
The Luhn algorithm, commonly known as the Mod 10 algorithm, is a simple checksum formula developed in 1954 by IBM scientist Hans Peter Luhn. It is widely used to validate identification numbers against accidental keystroke errors, mistyped digits, and single-digit errors.
Most credit card numbers (Visa, Mastercard, American Express, Discover), cellular IMEI numbers, National Provider Identifiers (NPI), and Canadian Social Insurance Numbers (SIN) rely on the Luhn check digit. For dedicated payment card checks, you can also use our Credit Card Validator and Credit Card Generator.
How the Luhn Algorithm Works Step-by-Step
To validate a numeric string using the Luhn mod 10 formula:
- Start from the rightmost digit: The very last digit on the right is the check digit. Keep it as position 1.
- Double every second digit: Moving from right to left, multiply every second digit (positions $2, 4, 6, 8, \dots$) by $2$.
- Sum the digits of the products: If doubling results in a two-digit number ($\ge 10$), subtract $9$ from it (which equals the sum of its digits, e.g., $7 \times 2 = 14 \to 1 + 4 = 5$ or $14 - 9 = 5$).
- Add all processed numbers together: Sum all modified and unmodified digits.
- Check Modulo 10: If the total sum modulo 10 is equal to zero ($\text{Total Sum} \pmod{10} = 0$), the number is valid under the Luhn algorithm.
Worked Example: Validating `79927398713`
| Original Digit | $7$ | $9$ | $9$ | $2$ | $7$ | $3$ | $9$ | $8$ | $7$ | $1$ | $3$ |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Position (from right) | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 (Check) |
| Multiplier | $\times 1$ | $\times 2$ | $\times 1$ | $\times 2$ | $\times 1$ | $\times 2$ | $\times 1$ | $\times 2$ | $\times 1$ | $\times 2$ | $\times 1$ |
| Raw Product | $7$ | $18$ | $9$ | $4$ | $7$ | $6$ | $9$ | $16$ | $7$ | $2$ | $3$ |
| Luhn Processed Value | $7$ | $9$ | $9$ | $4$ | $7$ | $6$ | $9$ | $7$ | $7$ | $2$ | $3$ |
Summing all processed values:
$$7 + 9 + 9 + 4 + 7 + 6 + 9 + 7 + 7 + 2 + 3 = 70$$Because $70 \pmod{10} = 0$, the number `79927398713` is mathematically VALID.
How to Calculate a Missing Check Digit
If you have a payload number (for instance, a newly generated account number $7992739871$) and want to compute the final check digit $C$:
- Multiply alternate digits starting with the rightmost payload digit by $2$.
- Sum all the resulting values. For $7992739871$, the payload sum is $67$.
- Calculate the check digit: $$C = (10 - (67 \pmod{10})) \pmod{10} = (10 - 7) = 3$$
- The full valid number is $79927398713$.
What Types of Errors Does Luhn Detect?
- Single-digit substitution errors: Detects $100\%$ of single-digit typos (such as typing $79927398713$ as $79927498713$).
- Adjacent transposition errors: Detects almost all adjacent transposition errors (such as swapping $98$ to $89$), except for $09 \leftrightarrow 90$.
- Twin errors: Detects twin error patterns such as $22 \leftrightarrow 55$ or $33 \leftrightarrow 66$.
Frequently Asked Questions
Is the Luhn algorithm a cryptographic hash?
No. The Luhn algorithm is an error-detecting checksum, not a cryptographic security measure. It is designed to prevent unintentional typing mistakes and format errors, not malicious tampering or forgery.
Why do we subtract 9 when doubling exceeds 9?
Subtracting 9 is mathematically identical to adding the two decimal digits of the product ($10a + b \to a + b$ since $10a + b - 9a = a + b$). For example, $16 \to 1 + 6 = 7$, and $16 - 9 = 7$.
Which organizations and industries use the Luhn formula?
The Luhn algorithm is standardized under ISO/IEC 7812-1. It is used worldwide by payment card issuers (Visa, Mastercard, Amex, Discover, JCB), telecommunications equipment providers for IMEI numbers, healthcare systems for NPI numbers, and government identification programs.
Can Luhn algorithm detect all errors?
While Luhn catches $100\%$ of single-digit errors and over $98\%$ of adjacent transposition errors, it cannot detect transposed $09 \leftrightarrow 90$ or complex multi-digit transposition permutations that sum to multiples of 10.