A Luhn formula test example runs a number through four moves: double every second digit starting from the right, subtract 9 from any result above 9, add all the digits together, and check whether the total is divisible by 10. The standard test case is 79927398713, which totals 70 and therefore passes. If the total had ended in any digit other than 0, the number would fail the check.

Luhn Algorithm Validation Test

The Luhn formula test example in full

Take the sequence 7992739871 plus a check digit of 3, written as 79927398713. Working from the rightmost digit, every second position gets doubled. The rightmost digit is the check digit itself and stays as it is.

more on this topic

  • Position 1 from the right: 3, unchanged, contributes 3
  • Position 2: 1 doubled to 2, contributes 2
  • Position 3: 7 unchanged, contributes 7
  • Position 4: 8 doubled to 16, minus 9 gives 7
  • Position 5: 9 unchanged, contributes 9
  • Position 6: 3 doubled to 6, contributes 6
  • Position 7: 7 unchanged, contributes 7
  • Position 8: 2 doubled to 4, contributes 4
  • Position 9: 9 unchanged, contributes 9
  • Position 10: 9 doubled to 18, minus 9 gives 9
  • Position 11: 7 unchanged, contributes 7

The total is 3 + 2 + 7 + 7 + 9 + 6 + 7 + 4 + 9 + 9 + 7 = 70. Since 70 mod 10 equals 0, the number passes.

luhn algorithm check test

Turning the test into a failing example

Change the final digit from 3 to 2 and the number becomes 79927398712. The only difference in the sum is one unit, so the total drops to 69. Because 69 mod 10 is 9, the number fails. That single-digit edit is exactly the kind of typo the check digit is designed to catch.

luhn algorithm verification test

Generating a check digit instead of verifying one

The same arithmetic works in reverse. Suppose you have the payload 7992739871 and need to find its check digit. Temporarily place a 0 in the check position and run the calculation: the sum becomes 67. Subtract the last digit of that sum from 10, which gives 10 minus 7, or 3. That is the digit you append, and it restores the total to a multiple of 10.

Step-by-step procedure you can repeat

  1. Write the number out and mark the rightmost digit as the check digit.
  2. Move left one position at a time, doubling every second digit.
  3. If a doubled value is 10 or higher, subtract 9 from it. Summing the two digits of that value gives the same answer.
  4. Add the untouched digits and the adjusted ones into a single running total.
  5. Divide the total by 10. A remainder of 0 means the number is consistent with the Luhn formula. Any other remainder means it is not.

What the Luhn test does not do

The check is a typing-error filter, not a security control. It has known blind spots worth memorizing before you rely on it.

  • It cannot detect a transposition of 09 into 90, because both arrangements produce the same adjusted total.
  • It says nothing about whether an account exists, is active, or belongs to the person submitting it.
  • It accepts roughly one in ten random digit strings, so passing the test carries limited weight on its own.
  • It does not verify length, issuer prefix, or any other numbering rule, which live in separate specifications.

Where the mod 10 check appears

Payment card numbers carry a Luhn check digit as part of their numbering standard. Mobile equipment identity numbers use the same check. National provider identifiers, Canadian social insurance numbers, and several national identity schemes also apply it. Because the rule is public and simple, it shows up in form validation code, spreadsheet formulas, and test suites whenever a developer needs a fast sanity check on a numeric string before sending it further down a pipeline.

Reading a Luhn result correctly

When a test example passes, the correct conclusion is narrow: the digits are internally consistent. When it fails, the number was almost certainly mistyped or corrupted, and there is no reason to process it. Treat the outcome as a first-pass filter that saves keystrokes and network calls, and pair it with the real validation your systems require.