Luhn Algorithm Calculator

Check whether a number passes the Luhn (mod 10) checksum, or generate the correct check digit for a number that is missing one.

Quick Facts

Doubling rule
Double every 2nd digit from the right
If doubling gives a two-digit result, subtract 9 (same as adding the two digits together).
Validity rule
Sum of all digits mod 10 = 0
A number passes the Luhn check only if this total is an exact multiple of 10.
Used by
Credit/debit cards, IMEI, SIN, more
Published by IBM scientist Hans Peter Luhn in 1954; also called the "mod 10" algorithm.

Your Results

Calculated
Luhn Result
-
Valid/invalid, or the generated check digit
Cleaned Digits
-
Spaces and dashes removed
Digit Count
-
Digits evaluated by the algorithm
Luhn Checksum
-
Sum after doubling, mod 10

Ready

Choose a mode, enter a number, then press Calculate.

How the Luhn Algorithm Works

The Luhn algorithm, also known as the "mod 10" or "modulus 10" checksum, is a simple formula for validating a string of digits. It was published by IBM scientist Hans Peter Luhn in 1954 and is still the check-digit standard for credit and debit card numbers, IMEI numbers on mobile devices, Canadian Social Insurance Numbers, and many other identifiers. This calculator either checks whether an existing number (including its final check digit) is Luhn-valid, or computes the correct check digit to append to a number that does not have one yet.

Formula and method

To validate a number, start from its rightmost digit (the check digit) and move left. Double the value of every second digit — that is, digits in positions 2, 4, 6, … counted from the right. If doubling a digit produces a number greater than 9 (for example 7 × 2 = 14), subtract 9 from it (14 − 9 = 5), which is mathematically the same as adding its two digits together (1 + 4 = 5). Add up every digit in the number — the doubled ones (after the correction) and the untouched ones. The number is Luhn-valid only if that grand total is an exact multiple of 10 (total mod 10 = 0). To generate a missing check digit instead, run the same doubling pattern over the number without its check digit, but start doubling from its last digit, since that digit becomes second-from-the-right once the check digit is appended. Sum the results, then the check digit is the value from 0-9 that brings the grand total up to the next multiple of 10.

Common sources of error

  • Doubling the wrong digits: the pattern always counts from the rightmost digit inward, so it flips depending on whether the number has an even or odd digit count.
  • Forgetting the subtract-9 step: if a doubled digit is 10 or higher, you must subtract 9 (or sum its digits) before adding it to the total — using the raw doubled value gives a wrong checksum.
  • Including formatting characters: spaces and dashes in a card or ID number must be stripped before the algorithm is applied; letters are not valid Luhn input.

Checking your result

A quick sanity check: the final checksum total should always be a two- or three-digit number ending exactly on a multiple of 10 (for example 40, 50, 60) when the number is valid. If you generate a check digit, appending it and re-running validation on the full number should always report "valid" — that round-trip is a fast way to confirm your arithmetic.

Applications

Luhn validation is built into point-of-sale systems, e-commerce checkout forms, and mobile network provisioning to catch typos and transcription errors before a transaction is attempted — a mistyped card number fails Luhn instantly rather than being sent to a payment processor. It is a data-integrity check, not a security or fraud check: a number can be perfectly Luhn-valid and still not correspond to a real, active account, and the algorithm cannot detect every possible error (it misses the specific transposition of "09" swapped to "90").

Frequently Asked Questions

What is the Luhn algorithm?
The Luhn algorithm (also called the mod 10 or modulus 10 algorithm) is a checksum formula published by IBM scientist Hans Peter Luhn in 1954. It is used to validate identification numbers such as credit and debit card numbers, IMEI numbers on phones, and Canadian Social Insurance Numbers, catching most single-digit typos and adjacent digit swaps.
How does the Luhn check digit work?
Starting from the rightmost digit (the check digit) and moving left, double every second digit. If doubling produces a two-digit number, subtract 9 from it (or add its two digits together). Sum all the digits, doubled and undoubled. The number is Luhn-valid only if that total is an exact multiple of 10.
How do I calculate a missing check digit?
Apply the same doubling pattern to the number without its check digit, but starting the doubling from its last digit (since that digit will sit second-from-the-right once the check digit is appended). Sum the results, then the check digit is whatever value (0-9) makes the grand total a multiple of 10.
Can the Luhn algorithm catch every data-entry error?
No. Luhn reliably detects any single altered digit and most transpositions of adjacent digits, but it cannot detect the transposition of 09 and 90, and it is not a fraud or security check — it only confirms a number is internally consistent, not that it belongs to a real account.