A Luhn check test is a checksum calculation that tells you whether a string of digits is internally consistent. It catches most single-digit typos and most swapped adjacent digits, but it says nothing about whether the number is real, active, or tied to anyone. The whole test is one pass over the digits, so it runs in microseconds on any device.

What the Luhn check test actually verifies

The Luhn algorithm, also called mod 10, was designed by Hans Peter Luhn at IBM in the 1950s. It takes a sequence of digits, applies a fixed doubling rule to every second digit, sums the results, and checks whether the total divides evenly by 10. If the remainder is zero, the number passes. If not, at least one digit is wrong or out of order.

The test is a format check. It exists to catch transcription errors before a number travels further into a system, such as a card number being typed at checkout or an IMEI being read off a device label.

How the Luhn algorithm works, step by step

  1. Write the digits in order, left to right.
  2. Starting from the rightmost digit, double every second digit (the rightmost digit itself is not doubled).
  3. If a doubled value is 10 or more, subtract 9 from it so it becomes a single digit.
  4. Add all the resulting digits together, including the ones you did not double.
  5. If the total ends in 0, the number passes the Luhn check test. Any other ending means it fails.

The same rule works in reverse when you need to generate a check digit: run the steps on the payload, take the total, and add whatever digit brings the sum up to the next multiple of 10.

A worked example

Take the payload 7992739871 and find its check digit. Doubling every second digit from the right gives 1 to 2, 8 to 16 to 7, 3 to 6, 2 to 4, and 9 to 18 to 9, which sum to 28. The digits left alone are 7, 7, 9, 7 and 9, which sum to 39. The combined total is 67, so the check digit is 3 and the finished number is 79927398713. Run the full number back through the test and the total lands on 70, a clean multiple of 10.

Where you will run into a Luhn check

  • Payment card numbers, which follow ISO/IEC 7812 numbering and always end in a Luhn check digit.
  • IMEI numbers on mobile devices.
  • Some national identification and account numbering schemes.
  • Serial numbers and tracking codes that need a cheap typo guard.
  • Test suites and sandboxes, where published sample numbers such as 4111 1111 1111 1111 are used to exercise checkout flows.

What a passing Luhn check does not tell you

Passing the test only means the digits add up. It does not confirm that an account exists, that a card is active, that a device is registered, or that the number was issued by anyone. A random sequence has roughly a one in ten chance of passing by accident.

This distinction matters in software design. A Luhn validation step belongs in the form layer to stop obvious typos, not in the authorization layer. Real verification always requires a request to the issuing system.

Common mistakes when running a Luhn test

  • Doubling from the left instead of from the right, which flips the parity for odd-length inputs.
  • Forgetting to subtract 9 from doubled values above 9, which inflates the sum.
  • Including spaces, dashes, or letters in the digit stream instead of stripping them first.
  • Assuming the test catches every transposition. Swapping 0 and 9 in adjacent positions still passes.
  • Treating a pass as proof of validity rather than proof of correct formatting.

Running the test by hand or in code

For a single number, the five steps above take about a minute with a pen. In code, a loop over the characters with a doubling flag is enough, and precomputed doubling tables make it faster for bulk checks. A variant called Luhn mod N extends the same idea to alphabetic identifiers, which is useful when codes mix letters and digits. Whichever version you use, the output is binary: the number passes or it does not.