Luhn Algorithm Checker
: Check a credit card number, IMEI or any mod 10 number with the Luhn algorithm, work out a check digit, and see the card network, for one number or a listLuhn Algorithm Checker
The Luhn algorithm (mod 10) is the check-digit formula behind credit and debit card numbers, IMEI phone numbers, Canadian Social Insurance Numbers and many account and ID numbers. This Luhn checker tells you whether a number passes, shows the working digit by digit, works out the check digit to add to a number that has none, names the card network from the leading digits, and checks a pasted list in bulk. It works as a credit card number validator for developers and testers: the number is checked in your browser and never sent anywhere.
How to check a number with the Luhn algorithm
- Choose
Check a numberwhen the last digit is the check digit, orAdd a check digitto work out the digit to put on the end. - Type or paste the number. Spaces, hyphens and dots between digits are ignored, so
4111 1111 1111 1111and4111-1111-1111-1111are the same number. - Read
Luhn check(ValidorNot valid) andCheck digit: when the number fails, it gives the digit the last place should hold and theCorrected number. InAdd a check digitmode, readCheck digitand copyNumber with check digit. - Read
Card networkandLength: the network comes from the leading digits, and a length that does not fit that network is pointed out. TheLuhn workingtable shows each digit, which ones are doubled and what each adds to the total. - For many numbers, set
InputtoA list, one per line. TheResultstable gives each line's status and card network (a failing line tinted amber, a line that is not a number red), 100 rows at a time with a search box; copy the valid or corrected numbers, or download the table as CSV.
Example
The working for Wikipedia's Luhn example 7992739871 (check digit 3), then a short list in Check a number mode: two test card numbers, one with its last digit mistyped, and an IMEI.
7992739871
4111 1111 1111 1111
4111 1111 1111 1112
378282246310005
4901542032375187 → 7
9 ×2 = 18 → 9
9 → 9
2 ×2 = 4 → 4
7 → 7
3 ×2 = 6 → 6
9 → 9
8 ×2 = 16 → 7
7 → 7
1 ×2 = 2 → 2
total 67 → (10 − 7) mod 10 = 3
4111 1111 1111 1111 valid · Visa
4111 1111 1111 1112 fails Luhn (check digit 2, should be 1) · Visa
378282246310005 valid · American Express
490154203237518 valid · Visa (length does not fit)Details
- The Luhn formula: starting from the rightmost digit (the check digit) and moving left, keep the first digit, double the second, keep the third, double the fourth, and so on. A doubled value over 9 has 9 taken off, which is the same as adding its two digits (16 becomes 1 + 6 = 7). The number passes the Luhn check when the total is a multiple of 10.
- To work out a Luhn check digit for a number that has none yet, double from its rightmost digit instead, total as above, and take
(10 − total mod 10) mod 10: the digit that brings the total up to the next multiple of 10. - The check catches every single mistyped digit and almost every swap of two neighbouring digits (all but
09and90). It cannot catch every error: two mistakes can cancel out. - Card networks are named from the issuer identification number (the leading digits): Visa (4), Mastercard (51–55 and 2221–2720), American Express (34, 37), Discover (6011, 644–649, 65), JCB (3528–3589), Diners Club, UnionPay (62), Maestro, Mir, RuPay, Dankort, InterPayment, Troy and UATP, with the lengths each uses (Visa 13, 16 or 19 digits; American Express 15; Mastercard 16). The longest matching prefix wins, so
6011is Discover, not RuPay's60. - No card network matched? A 15-digit number is the length of an IMEI, whose 15th digit is a Luhn check digit (the IMEISV, 16 digits, has none); a 9-digit one is the length of a Canadian SIN. The IMEI note also shows when the leading digits fall in a card range at a length that network never uses, as
490154203237518does in Visa's. - In the list, blank lines are skipped, and a card network whose lengths do not include the number's is shown as, for example,
Visa (length does not fit).Copy correctedgives the failing numbers with the last digit replaced by the right check digit, which is only the right fix when the last digit was the typo. The CSV has the columnsinput,digits,status,right_check_digit,correctedandnetwork(inAdd a check digitmode:input,digits,check_digit,with_check_digit,network).
Limits
- A number that passes Luhn was not mistyped; that is all it proves. It does not show that a card exists, is open or has money on it, and nothing here contacts a bank or card network. The expiry date and CVV are not part of the Luhn check and are not asked for.
- Card network ranges change as schemes add and move prefixes. They follow the issuer identification number table on Wikipedia's Payment card number article; a co-branded or regional card may be named by the larger scheme whose range it falls in.
- Only the plain Luhn mod 10 check on digits. Barcode check digits (UPC, EAN, GTIN) use weights of 3 and 1, ISBN-10 uses mod 11, and Luhn mod N for letters is different again; Australian NMIs have their own NMI checksum.
- The
Luhn workingtable is drawn for numbers up to 120 digits; a longer number is still checked in full.
FAQ
How does the Luhn algorithm work?
From the right, keep the check digit, double every second digit after it, take 9 off any doubled value over 9, and add everything up. If the total ends in 0 the number is valid: 79927398713 totals 70, so it passes.
How do I calculate a Luhn check digit?
Choose Add a check digit and type the number without it. Starting from the rightmost digit, every second digit is doubled, the total is taken, and the check digit is what brings it up to the next multiple of 10: 7992739871 totals 67, so its check digit is 3.
Is this credit card validator safe to use with a real card number?
The number is checked by code running in your browser; it is not sent, stored or logged anywhere. Even so, there is no need to type a real card: the Luhn check works the same on the published test numbers such as 4111 1111 1111 1111 (Visa) and 5555 5555 5555 4444 (Mastercard).
Do all credit cards use the Luhn algorithm?
Almost all: Visa, Mastercard, American Express, Discover, JCB, Diners Club, Maestro, Mir and RuPay numbers end in a Luhn check digit, and so do most UnionPay cards. Gift and store cards outside these schemes may use no check digit at all.
Can I check an IMEI number with the Luhn algorithm?
Yes. A 15-digit IMEI ends in a Luhn check digit, so Check a number confirms it was typed correctly, and Add a check digit gives the 15th digit from the first 14. It says nothing about whether a phone is blocked or reported stolen.
Runs entirely in your browser. Nothing is uploaded.