What Are Credit Card Numbers and the Luhn Algorithm? Step-by-Step Validation
Updated: October 13, 2026 · AracMerkezi
▶ Open Credit Card Number Checker (Luhn)
When you mistype the last digit of your card number on a shopping site, the form shows an "invalid card number" warning before you even press the pay button. Behind this is a small, purely mathematical check that never goes to the bank: the Luhn algorithm. In this guide we explain which parts a card number is made of, how the Luhn algorithm works step by step, hand-worked examples, what the algorithm does and does not verify, points to watch out for in terms of security, and form validation recommendations for developers.
Important note and security warning: This article has been prepared for informational purposes. Never share your real card number, expiration date and CVV code with anyone or with sites you do not trust, under any circumstances. This article uses only publicly known test numbers; they do not belong to a real account.
Structure of a card number
Credit and debit card numbers are generally between 13 and 19 digits long; the most common length is 16 digits. According to the international ISO/IEC 7812 standard, the number consists of three parts:
- First digit (MII): Shows the industry type of the card. Banking and financial cards start with digits such as 4 and 5.
- Issuer identification number (BIN or IIN): Usually the first 6 digits (8 under newer rules); it identifies the issuing institution and the card network. For example, numbers starting with 4 are mostly on the Visa network and those starting between 51 and 55 are on the Mastercard network; however, this distinction should be read as general information, not as a strict rule.
- Account number: The part assigned to the card by the bank, forming the middle digits; it does not have to be exactly the same as the customer's account number.
- Check digit: The last digit of the number, calculated from the other digits using the Luhn algorithm.
The number of digits varies by network. For example, an Amex number used for testing has 15 digits; Visa and Mastercard numbers generally have 16 digits. On the card the number appears in groups of four; this is only for readability and has no effect on the algorithm.
What is the Luhn algorithm?
The Luhn algorithm (mod 10 algorithm) is a simple checksum method developed in 1954 by IBM engineer Hans Peter Luhn. Besides credit cards, it is also used in some ID and tracking numbers. Its purpose is not to provide security but to catch typing errors: it detects, to a large extent, common human mistakes such as a single wrong digit or the swap of two neighboring digits.
How it works, step by step
To check whether a number is correct, follow these steps:
- Read the number from right to left; the rightmost check digit is position 1.
- Multiply the digits in even positions, such as 2nd, 4th, 6th, by 2.
- If the product is greater than 9, add its digits (or subtract 9); for example, 16 → 1+6 = 7 or 16 − 9 = 7.
- Find the sum of all the digits (the modified and unmodified ones).
- If the total is exactly divisible by 10, the number passes the Luhn check.
### Example 1: A short number, 79927398713
This is the classic example used to explain the Luhn algorithm. Let's process the number from right to left; the rightmost 3 is position 1 (unchanged), the 1 is position 2 (even position, multiplied by 2), and so on.
Digits from right to left: 3, 1, 7, 8, 9, 3, 7, 2, 9, 9, 7.
- Digit 1: 3 (unchanged) → 3
- Digit 2: 1 × 2 = 2
- Digit 3: 7 → 7
- Digit 4: 8 × 2 = 16 → 1 + 6 = 7
- Digit 5: 9 → 9
- Digit 6: 3 × 2 = 6
- Digit 7: 7 → 7
- Digit 8: 2 × 2 = 4
- Digit 9: 9 → 9
- Digit 10: 9 × 2 = 18 → 1 + 8 = 9
- Digit 11: 7 → 7
Sum: 3 + 2 + 7 + 7 + 9 + 6 + 7 + 4 + 9 + 9 + 7 = 70. Because 70 is exactly divisible by 10, the number is valid. If you change the last digit to 0 (79927398710), the sum becomes 67 and the number is considered invalid; in other words, the correct check digit is 3.
### Example 2: The well-known test number 4111 1111 1111 1111
This number is widely used for testing in payment systems. Since it has 16 digits, the first digit on the left is position 16 and is in an even position. The digits in even positions (the 1st, 3rd, 5th, ... digits from the left, that is 4, 1, 1, 1, 1, 1, 1, 1) are doubled:
- 4 × 2 = 8
- the other seven 1 × 2 = 2; seven 2s → 14
Unchanged digits (the 2nd, 4th, ..., 16th digits from the left): eight 1s → 8.
Sum: 8 + 14 + 8 = 30. Since 30 is a multiple of 10, the number passes the Luhn check. If the last digit were 2 (4111 1111 1111 1112), the sum would be 31 and it would come out invalid.
### Other well-known test numbers
- 5555 5555 5555 4444 (Mastercard test): sum 60, valid.
- 3782 822463 10005 (Amex test, 15 digits): sum 60, valid.
- 4012 8888 8888 1881 (Visa test): sum 90, valid.
These are all test numbers published openly in documentation; they do not make a real payment.
What does the Luhn algorithm verify?
- That the number is formally consistent: that is, that there is no typing error.
- It catches 100% of single wrong digits.
- It catches the swap of two neighboring digits in most cases (there are rare exceptions, such as swapping 09 and 90).
What does the Luhn algorithm not verify?
- That the card actually exists or belongs to a bank.
- That the card is active, unexpired or not blocked.
- Limit or balance information.
- The cardholder, or that you are the holder.
- Security: The algorithm is not secret; anyone can generate numbers that pass Luhn. So saying "it passed Luhn, so it is a real card" is wrong.
For a real payment, the number must obtain authorization from the bank, and additional verification such as the expiration date, the security code and 3D Secure is required. Luhn is only the first, very light link in this chain.
Security warnings
- Do not share your card number, expiration date and CVV code with anyone; not even a bank employee will ask for your CVV or SMS password.
- When paying, check for https and the correct domain name in the address bar; do not enter card details on payment pages reached through suspicious links.
- Do not share your card number as a screenshot in chat apps.
- In validation tools, try well-known test numbers instead of a real number whenever possible. The Credit Card Number Checker (Luhn) tool does not send the number off your device; the result is calculated in your browser. Even so, as a habit, not entering a real number is the safest way.
- If you suspect fraud, call your bank immediately and have the card blocked.
Form validation for developers
If you are writing a payment or registration form, a Luhn check improves the user experience:
- Strip spaces and hyphens from the input so that only digits remain.
- Check the length (usually 13-19 digits).
- Calculate the Luhn sum; if it does not pass, warn the user before any request is sent to the server.
- Use the check only as a pre-validation; real authorization is done at the payment provider.
- Do not store card numbers in your own database; use a payment infrastructure that complies with security standards such as PCI DSS, and do not write numbers to logs.
- Do not echo even part of the number back in the error message.
- In the test environment, use the publicly available test numbers above.
Common points of confusion
- Relationship with the IBAN: The IBAN is a different system and is validated with the mod 97 method; it should not be confused with a card number. For IBAN validation, you can look at the IBAN Checker tool.
- Calculating the check digit: If the last digit of a number is unknown, you first find the sum for the other digits, then choose as the check digit the digit that brings the sum up to a multiple of 10.
- Does every card use Luhn? Most major card networks do; however, there may be exceptions.
Conclusion
The Luhn algorithm is a small but effective tool for catching typing errors in card numbers. It does not show that a card is real; it only says that the number was written consistently. Think of validation and security as separate matters, and always keep your card details protected.
Related tools
You can quickly try the Luhn check with the Credit Card Number Checker (Luhn), verify IBAN numbers with the IBAN Checker, and use the Password Strength Checker tool to protect your accounts. For the IBAN, also take a look at the article What Is an IBAN and How Is It Checked?. This content is for general information; on card security, follow your bank's instructions.
Frequently asked questions
What is the Luhn algorithm?
Starting from the second digit from the right, every second digit is doubled, 9 is subtracted if the result is greater than 9, and all the digits are added up. If the total is exactly divisible by 10, the number is valid in format.
Does a Luhn check prove that the card is real?
No. It only catches typing errors, such as a digit entered incorrectly. It gives no information about whether the card exists, is active, or what its balance is.
Should I type my real card number into checking tools?
There is no need. A test number is enough for a format check. The safest approach is not to share your real card details, along with the CVV and expiration date, on any site.
Tools mentioned in this guide
More guides
- What Is an IBAN? Structure and How to Validate It (Mod 97) – What is an IBAN and how is a Turkish IBAN structured? Step-by-step mod 97 validation with a real example, plus what the check does and does not catch.
- How to Create a Secure Password: Length, Entropy and 8 Rules – How to create a secure password: password strength in bits, random-word passphrases, command-line generation and eight practical rules.
- How Do You Read a Barcode (EAN-13)? How Is the Check Digit Calculated? – EAN-13 barcode structure, prefix, company and product code, a check digit example, the link to ISBN, and how it differs from the Luhn algorithm.
- Email Address Validation: How to Check for a Valid Email – Valid email address format, common mistakes, the limits of regex validation and form tips. A format check does not prove that an address actually exists.
- How to Spot a Phishing Email: Protection Guide – How to spot a phishing email? 10 signs of fake messages, how to check a link, first steps if you clicked, and how to report to USOM, Turkey's cyber response center.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.