TR

Home / Guides / What Are Credit Card Numbers and the Luhn Algorithm? Step-by-Step Validation

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:

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:

  1. Read the number from right to left; the rightmost check digit is position 1.
  2. Multiply the digits in even positions, such as 2nd, 4th, 6th, by 2.
  3. If the product is greater than 9, add its digits (or subtract 9); for example, 16 → 1+6 = 7 or 16 − 9 = 7.
  4. Find the sum of all the digits (the modified and unmodified ones).
  5. 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.

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:

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

These are all test numbers published openly in documentation; they do not make a real payment.

What does the Luhn algorithm verify?

What does the Luhn algorithm not verify?

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

Form validation for developers

If you are writing a payment or registration form, a Luhn check improves the user experience:

Common points of confusion

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

This article is for general information only and is not legal, financial or medical advice. We are not an official institution.