Luhn Algorithm Calculator

Luhn Algorithm Calculator

Growing AI Skill PRO

Enter Calculation

Formula

Valid⇔(∑i=0n−1f(di))mod10=0where{di=i-th digit of Number (from right)f(di)={dii even2di−9[2di>9]i odd\text{Valid} \iff \left(\sum_{i=0}^{n-1} f(d_i)\right) \bmod 10 = 0 \\[1.5em] \text{where}\quad \left\{ \begin{aligned} d_i &= i\text{-th digit of } \text{Number} \text{ (from right)} \\ f(d_i) &= \begin{cases} d_i & i \text{ even} \\ 2d_i - 9\,[2d_i>9] & i \text{ odd} \end{cases} \end{aligned} \right.
Usage stats

Advertisement

Results

Luhn Check
VALID
Number of digits 11
Luhn sum 70
Sum mod 10 0
Check digit (last) 3

Report an error on this page

What is the Luhn Algorithm?

The Luhn algorithm, also called the "mod 10" algorithm, is a simple checksum formula created by IBM scientist Hans Peter Luhn in 1954. It is used to validate identification numbers such as credit and debit card numbers, IMEI phone serial numbers, and many national identification numbers. It detects single-digit errors and most transposition mistakes, but it is not a cryptographic security measure — only a basic data-integrity check.

How to Use This Calculator

Type the number you want to verify into the field (spaces and dashes are ignored automatically). The calculator processes the digits, applies the Luhn checksum, and tells you whether the number is VALID or INVALID, along with the running sum, the sum modulo 10, and the trailing check digit.

The Formula Explained

Read the digits from right to left. Leave the rightmost (check) digit as-is, then double every second digit. If doubling produces a number greater than 9, subtract 9 from it (equivalent to adding the two digits, e.g. \(8\times2=16 \to 1+6=7\)). Add up every resulting value. If the total is divisible by 10, the number passes the Luhn check.

$$\text{Valid} \iff \left(\sum_{i=0}^{n-1} f(d_i)\right) \bmod 10 = 0 \\[1.5em] \text{where}\quad \left\{ \begin{aligned} d_i &= i\text{-th digit of } \text{Number} \text{ (from right)} \\ f(d_i) &= \begin{cases} d_i & i \text{ even} \\ 2d_i - 9\,[2d_i>9] & i \text{ odd} \end{cases} \end{aligned} \right.$$
Advertisement
Flat diagram showing Luhn algorithm digit doubling from the right, with alternate digits doubled and summed
The Luhn algorithm doubles every second digit from the right, then sums all digits.

Worked Example

Take the number 79927398713. Doubling every second digit from the right and reducing values over 9 yields the adjusted digits whose total is 70. Since \(70 \bmod 10 = 0\), the number is valid.

Flat flowchart showing the Luhn check ending in a mod 10 test branching to valid or invalid
If the total sum is divisible by 10, the number is valid.

Common Number Types That Use the Luhn Check

The Luhn (mod 10) algorithm is an error-detecting checksum. The last digit of the number is a check digit chosen so the whole number passes. The table lists widely used formats that include it. Prefixes and lengths follow the ISO/IEC 7812 numbering scheme and each issuer's published rules.

Format Typical prefix (IIN/BIN range) Length (digits) Luhn check digit?
Visa 4 13, 16 or 19 Yes
Mastercard 51–55 and 2221–2720 16 Yes
American Express 34 or 37 15 Yes
Discover 6011, 65, 644–649 16 (up to 19 on some cards) Yes
Diners Club 300–305, 36, 38–39 14 to 19 (14 is common) Yes
JCB 3528–3589 16 (up to 19 on some cards) Yes
IMEI (mobile device identifier) Begins with an 8-digit Type Allocation Code 15 Yes, the 15th digit is the Luhn check digit
Canadian Social Insurance Number (SIN) First digit indicates province/region group 9 Yes
South African ID number Starts with birth date (YYMMDD) 13 Yes, the last digit is a Luhn check digit

Important notes:

  • Passing the Luhn check does not identify the issuer or the type of number. A random string of digits passes about 1 time in 10. The prefix and length are what indicate a card brand.
  • Not all identifiers use Luhn. Many national ID numbers use other checksums, such as weighted mod 11 or mod 97. Do not assume a number is invalid just because it fails Luhn if its format does not use it.
  • Card prefixes and lengths are changed by issuers from time to time, so treat the table as a general guide.

Step-by-Step Calculation by Hand

Example: validate 79927398713, a commonly used test number.

  1. Write the digits right to left and number the positions from 0. Position 0 is the check digit (3):
    pos 0 = 3, pos 1 = 1, pos 2 = 7, pos 3 = 8, pos 4 = 9, pos 5 = 3, pos 6 = 7, pos 7 = 2, pos 8 = 9, pos 9 = 9, pos 10 = 7.
  2. Leave the even positions (0, 2, 4, …) unchanged: 3, 7, 9, 7, 9, 7.
  3. Double every second digit (odd positions 1, 3, 5, …). If the result is above 9, subtract 9 (this equals adding its two digits):
    • pos 1: 1 → 2
    • pos 3: 8 → 16 → 7
    • pos 5: 3 → 6
    • pos 7: 2 → 4
    • pos 9: 9 → 18 → 9
  4. Add everything: unchanged digits 3 + 7 + 9 + 7 + 9 + 7 = 42; processed digits 2 + 7 + 6 + 4 + 9 = 28. Total = 42 + 28 = 70.
  5. Apply mod 10: \(70 \bmod 10 = 0\), so the number is valid.

Calculating a check digit for a partial number

Suppose you have 7992739871 and need the final digit.

  1. Append a placeholder 0: 79927398710. The placeholder sits at position 0, so the original digits shift to positions 1 and up, and the doubling pattern is the same as above.
  2. Compute the sum with the placeholder contributing 0. Here the sum is \(70 - 3 = 67\).
  3. Check digit \(= (10 - (67 \bmod 10)) \bmod 10 = (10 - 7) \bmod 10 = 3\).
  4. The full number is 79927398713, which matches the valid example. The outer \(\bmod 10\) turns a result of 10 into 0 when the sum is already a multiple of 10.
Advertisement

Interpreting Your Result

  • VALID means the weighted digit sum is divisible by 10, so the number is well-formed. It does not mean the number has been issued, is active, belongs to anyone, or has funds or credit behind it.
  • INVALID means the sum mod 10 is not 0, which usually indicates a typo or a wrong digit. The nonzero remainder \(r\) shows the size of the discrepancy. If you suspect only the final digit is wrong, replacing it with \((d - r) \bmod 10\) (where \(d\) is the current last digit) makes the number pass. That is not necessarily the correct number, though.

What Luhn catches and misses

  • It detects all single-digit errors.
  • It detects most adjacent transpositions of digits. The exception is the swap of 09 ↔ 90.
  • It can miss some twin errors, such as 22 ↔ 55, 33 ↔ 66 and 44 ↔ 77.
  • It can miss other multi-digit errors, and roughly 1 in 10 random errors of that kind will still pass.

Not a security check: anyone can generate numbers that pass Luhn, so a VALID result says nothing about fraud, authorization, or ownership. Real payment verification is done by the card network and issuer. Never enter real card numbers into tools you do not trust; test numbers are enough for checking how the algorithm works.

FAQ

Does a valid Luhn result mean a card is real? No. It only confirms the number is well-formed; it does not check whether the account exists or has funds.

What characters are allowed? Only digits are used; spaces, dashes and other symbols are stripped before calculating.

Why subtract 9 when doubling? Subtracting 9 from a doubled digit over 9 gives the same result as summing its two digits, which is exactly what the original Luhn rule requires.

Last updated:

Most popular in Math and Statistics

View all Math and Statistics calculators