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").