Luhn check — validate a card or IMEI number, or work out its check digit

Enter a number to see if its last digit is a correct Luhn (mod 10) check digit, or switch mode to calculate the digit that should go on the end.

Live demo · real result from this tool
Mode
ResultValid
Check digit expected
2
Digits
16
Network (by prefix)
Visa

Processed on your device — nothing is uploaded.

How to use the Luhn validator

  1. Choose a Mode: Validate a full number or Compute the check digit.
  2. Type the digits into Number. Spaces and hyphens are ignored; letters are rejected.
  3. In validate mode, read Result (Valid or Invalid), the Check digit expected, the count of Digits and the Network (by prefix).
  4. 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:

  1. Double the rightmost digit, then every second digit moving left.
  2. If doubling gives more than 9, subtract 9 (the same as adding the two digits of 12 to get 3).
  3. Add all the digits, doubled and undoubled.
  4. 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?
No. About one in ten random numbers passes the Luhn test. It only shows the digits are self-consistent, not that an account exists, is active or has funds.
Which numbers use the Luhn algorithm?
Payment card numbers, IMEI numbers on phones, Canadian Social Insurance Numbers and many loyalty and gift card numbers. ISBNs and barcodes use different check-digit rules.
What mistakes does it catch?
Any single wrong digit, and almost every swap of two neighbouring digits. The one swap it misses is 09 and 90. It does not catch all double errors.
Should I type my real card number here?
The check runs only in your browser and nothing is sent, but for testing a form or a payment flow it is better to use published test numbers such as 4242 4242 4242 4242 or numbers from the test card generator.
How is the card network detected?
From the first digits only. For example 4 is Visa, 51–55 and 2221–2720 are Mastercard, 34 and 37 are American Express. Numbers starting 65 are shown as Discover or RuPay because both use that prefix. No bank lookup is made.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close