How to use the Luhn validator
- Choose a Mode: Validate a full number or Compute the check digit.
- Type the digits into Number. Spaces and hyphens are ignored; letters are rejected.
- In validate mode, read Result (Valid or Invalid), the Check digit expected, the count of Digits and the Network (by prefix).
- In compute mode, enter the number without its last digit. The tool shows the Check digit and the Full number.
What it does and when to use it
The Luhn formula, patented by IBM engineer Hans Peter Luhn in 1960, adds one check digit to the end of an identification number. Forms use it to catch typing mistakes before a number is sent to a bank or a database. Developers use it to validate input fields, to create realistic test data, and to debug numbers that a payment form rejects.
To make whole test numbers, use the IMEI generator or the test card generator linked above. For book numbers, which use a different rule, see the ISBN validator. Bank account numbers in IBAN format use a mod 97 check instead; the IBAN generator builds valid examples.
How it works
The code in this page works from the right-hand end of the number without its check digit:
- Double the rightmost digit, then every second digit moving left.
- If doubling gives more than 9, subtract 9 (the same as adding the two digits of 12 to get 3).
- Add all the digits, doubled and undoubled.
- The check digit is the amount needed to reach the next multiple of 10:
(10 − sum mod 10) mod 10.
To validate, the tool removes the last digit, computes what it should be, and compares.
Worked examples
The textbook number. Compute mode with 7992739871. From the right, the doubled digits are 1, 8, 3, 2 and 9, which become 2, 7, 6, 4 and 9 (sum 28). The other digits 7, 9, 7, 9 and 7 add up to 39. The total is 67, so the check digit is 3. The tool shows Check digit: 3 and Full number: 79927398713, and validating 79927398713 returns Result: Valid.
A typo in a test card. 4242 4242 4242 4241 returns Result: Invalid, Check digit expected: 2, 16 digits, network Visa. The real test number ends in 2.
A 15-digit IMEI. 490154203237518 returns Result: Valid with check digit 8. Its network shows Visa only because it starts with 4; the prefix rules are meant for cards.
Limits and tips
- Validation needs at least two digits.
- The network guess is prefix-only and covers Visa, Mastercard, American Express, Discover, RuPay, JCB, Diners Club and UnionPay.
- Card lengths are not checked, so a 12-digit number can still pass.
Frequently asked questions
Does a valid result mean the card is real?
Which numbers use the Luhn algorithm?
What mistakes does it catch?
Should I type my real card number here?
How is the card network detected?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.