Luhn Algorithm Calculator: Check Digits for Cards, SINs and IMEIs
By FindMySum · Last reviewed
A Luhn algorithm calculator checks whether a number passes the mod 10 test used by credit and debit cards, Canadian Social Insurance Numbers and phone IMEIs, or works out the check digit to add to the end of a number. The Luhn check is a simple way to catch typing mistakes: change any one digit, or swap two neighbouring digits, and the check almost always fails. This page shows every doubling step, guesses the type of number from its length and prefix, and runs entirely in your browser: the number you type is never put in the page address or share link and is not sent anywhere. The worked example uses the default, the textbook number 79927398713.
The algorithm step by step
To check 79927398713, work from the rightmost digit (the check digit, 3) to the left:
- Keep the rightmost digit as it is, then double every second digit: the 1, 8, 3, 2 and 9 (counting from the right).
- If a doubled digit is more than 9, subtract 9. 8 × 2 = 16 → 7; 9 × 2 = 18 → 9. Subtracting 9 is the same as adding the two digits of the result (1 + 6 = 7).
- Add everything up. The kept digits 3, 7, 9, 7, 9, 7 and the doubled-and-reduced digits 2, 7, 6, 4, 9 total 70.
- Check the total. 70 is a multiple of 10, so the number is valid.
The steps table on the page shows each digit, whether it was doubled, and what it adds to the total.
Computing a check digit
To create a number with a Luhn check digit, start from the number without it, 7992739871. Now the rightmost digit is the first to be doubled, because the check digit will sit to its right. The doubled-and-reduced digits plus the kept ones total 67. The check digit is whatever brings the total up to the next multiple of 10:
check digit = (10 − 67 mod 10) mod 10 = (10 − 7) mod 10 = 3
Append it to get 79927398713, which passes. The extra "mod 10" makes the check digit 0 rather than 10 when the total is already a multiple of 10.
What the check catches and misses
The Luhn check catches:
- every single-digit error, because changing one digit always changes the total by an amount that is not a multiple of 10;
- almost every swap of two neighbouring digits (a transposition), because one of the two is doubled and the other is not.
It misses the swap 09 ↔ 90, and most errors that change two digits at once. That is fine for its purpose: people mostly make single-digit and transposition errors when typing numbers.
What the check cannot do is tell you whether a number was ever issued. About one in ten random numbers of the right length passes. A passing card number may be fictional, cancelled or someone else's; only the issuing bank can authorise a payment.
Card numbers and brands
A payment card number (the primary account number) starts with an issuer identification number. The first digit is the major industry identifier: 4 and 5 are banking and financial, 3 travel and entertainment, 6 merchandising and banking. The brand follows from the first few digits and the length:
| Brand | Starts with | Length |
|---|---|---|
| Visa | 4 | 13, 16 or 19 |
| Mastercard | 51–55, 2221–2720 | 16 |
| American Express | 34, 37 | 15 |
| Discover | 6011, 644–649, 65 | 16–19 |
Mastercard added the 2221–2720 range (six-digit BINs 222100–272099) in 2017 because it was running out of 5-series numbers. Canadian bank cards are usually co-badged Visa Debit or Debit Mastercard and follow those prefixes; Interac-only cards use bank-specific ranges that this page doesn't try to name.
Social Insurance Numbers
A Canadian SIN has nine digits, and the ninth is a Luhn check digit, so the same test catches most typos on payroll and tax forms. A SIN beginning with 9 is issued to temporary residents, such as international students and temporary foreign workers, and expires with their permit. A number that passes the check is not proof that a SIN is valid or belongs to the person giving it; employers confirm identity with documents, not arithmetic.
Because a SIN is sensitive personal information, this page never adds the number to the URL, the share link or your browser history, and the calculation never leaves your device. When you share the page, only the mode (validate or check digit) is in the link.
IMEIs
Every mobile phone has a 15-digit IMEI, shown by dialling *#06#. The first eight digits are the type allocation code, which identifies the make and model, the next six are the serial number, and the fifteenth is a Luhn check digit over the first fourteen. The example 490154203237518 passes. Carriers use the IMEI to block stolen phones, which the Luhn check knows nothing about.
More questions
Who invented the Luhn algorithm?
Hans Peter Luhn, an IBM engineer, patented it in 1960 (US Patent 2,950,048, filed 1954) as a computer for verifying numbers. The patent has long expired, so anyone can use it, and it became part of the ISO/IEC 7812 standard for identification cards.
Why do online forms reject my card number before I submit?
Most checkout forms run the Luhn check in the browser and also check the length and prefix. If you mistype one digit, the form can tell immediately without contacting the bank. A rejected number almost always means a typo; a number that passes can still be declined later by the bank.
What other numbers use a check digit?
Many: Canadian SINs and business numbers, IMEIs, some loyalty and gift cards use Luhn; ISBNs and UPC barcodes use weighted sums with mod 11 or mod 10; IBANs use mod 97. Each scheme catches different kinds of typing errors.
Can I generate valid card numbers with the Luhn check?
You can make numbers that pass the check, but they are not cards: without an account at an issuer they can't be charged. Payment networks publish official test numbers, such as 4111 1111 1111 1111, for developers to use in test environments.
Is the Luhn algorithm a form of encryption?
No. It hides nothing and anyone can compute it. It is a checksum: a small piece of redundancy added to a number so that accidental errors are detected. Protecting a card number needs encryption and tokenisation, which payment systems use separately.
Sources
- ISO/IEC 7812-1:2017 Identification cards — Identification of issuers — Part 1: Numbering system (Annex B: Luhn formula for computing modulus-10 check digit)
- US Patent 2,950,048, H. P. Luhn, Computer for Verifying Numbers (1960)
- Government of Canada: Social Insurance Number for temporary residents (SINs starting with 9)
- 3GPP TS 23.003: Numbering, addressing and identification (Annex B: IMEI check digit)
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.