Credit Card Luhn Validator: Check a Number's Format, Nothing More

Every card number carries a built-in typo detector. The final digit is not random: it is a check digit chosen so that the whole number passes a simple arithmetic test called the Luhn algorithm. When you type a number and get one digit wrong, the test usually fails, which is how payment forms catch mistakes before they travel any further. It is a clever, lightweight piece of design, and it is also widely misunderstood.

The Credit Card Luhn Validator runs that test. You enter a number and it tells you whether the number passes or fails the Luhn check. That is all it does. It does not verify a real card, it does not check an account, a balance, an expiry date, or an issuer, and it cannot tell you whether a card exists. Please never enter a real card number into this or any public checker: use only clearly fake sample numbers, such as the textbook example used below, when learning or testing the algorithm.

How it works

The algorithm works from right to left. Starting with the check digit itself and moving left, every second digit is doubled. If doubling produces a number greater than nine, nine is subtracted from it, which is the same as adding its two digits together. All the resulting digits are then added up. If the total is a multiple of ten, the number passes. If it is not, the number fails, which almost always means a digit was mistyped or misread.

The doubling step is what gives the test its power. A single wrong digit changes the total, and swapping two adjacent digits usually changes it too, because one of the pair is doubled and the other is not. The test is not perfect: swapping certain digit pairs, such as 09 and 90, can slip through, and a number can pass while still being entirely invented. Those limits are acceptable for a typo check, which is all the test was designed to be.

The check digit itself is chosen to make the arithmetic work. When a card number is issued, the issuer takes the other digits, runs the algorithm in reverse, and picks the final digit that brings the total to a multiple of ten. That is why changing only the last digit of a valid number almost always breaks the test, and why the test can detect a wrong final digit as reliably as a wrong digit anywhere else.

Worked example

Take the textbook sample number 79927398713, a clearly fake number used in teaching examples, not a real card. Work from the right, doubling every second digit. The digits from the right are 3, 1, 7, 8, 9, 3, 7, 2, 9, 9, 7. Doubling every second digit gives, from the right: 3 stays 3, 1 doubled is 2, 7 stays 7, 8 doubled is 16, which becomes 7 after subtracting 9, 9 stays 9, 3 doubled is 6, 7 stays 7, 2 doubled is 4, 9 stays 9, 9 doubled is 18, which becomes 9, and 7 stays 7.

Adding those results: 3 plus 2 plus 7 plus 7 plus 9 plus 6 plus 7 plus 4 plus 9 plus 9 plus 7 equals 70. Seventy is a multiple of ten, so the number passes. Change the final digit from 3 to 4, giving 79927398714, and the total becomes 71, which is not a multiple of ten, so the number fails. One digit changed, one test failed, which is exactly the behaviour a typo check needs.

  • Write the sample digits from the right and double every second digit, subtracting 9 from any result above 9.

  • Transformed digits from the right: 3, 2, 7, 7, 9, 6, 7, 4, 9, 9, 7.

  • Sum: 3 + 2 + 7 + 7 + 9 + 6 + 7 + 4 + 9 + 9 + 7 = 70.

  • 70 is a multiple of ten, so 79927398713 passes; changing the last digit to 4 gives 71, which fails.

Common mistakes to avoid

The most serious mistake is treating a pass as proof that a card is genuine. A passing number can be invented in seconds, and many published test numbers pass deliberately. Payment systems never accept a card on the Luhn test alone; they check the issuer, the account, the expiry, the security code, and the available balance through secure channels. Anyone who asks you to prove a card by running it through a public checker is not following a real verification process.

The second mistake is entering a real card number into a checker, a form, or a chat window to test it. Real card numbers should only ever be entered into the secure payment page of a legitimate merchant or bank. A third, smaller mistake is doubling from the wrong end: the doubling starts from the second digit from the right, not from the left, and starting from the left gives a different answer for numbers with an even digit count.

What it does not do

This validator checks format only. It cannot verify a real card or account, cannot detect fraud, cannot confirm an issuer, and cannot tell whether a number belongs to anyone. It is useful for learning the algorithm, for testing software that accepts card-shaped input, and for catching typing errors in a number you are already authorised to handle in a proper system. For any real payment question, use the card issuer or the merchant's secure payment system, never a public tool.

If you are building software, remember that passing the Luhn test is a necessary but trivial condition. Real validation happens server-side through the payment network, with encryption, authentication, and fraud checks that no browser tool can reproduce. Treat any client-side check as a courtesy to the user, not as a security control.

A short practical routine

A sensible routine for developers and learners is to test with the textbook sample numbers only, and to test both a passing and a failing case. Run 79927398713 and confirm a pass, then change one digit and confirm a fail. That pair of tests catches the most common implementation bug, which is doubling from the wrong end or forgetting to subtract nine. Keep a note of the two expected totals, 70 and 71, as your reference values.

For anyone handling real payments, the routine is different and simpler: never paste real numbers into test tools, and never store them in notes, spreadsheets, or chat logs. Use the payment provider's test numbers inside its own test environment, and keep real card handling inside systems designed for it. For related number checks, the Average Calculator covers ordinary arithmetic summaries, and the guide on How to Calculate an Average the Right Way explains how averages can mislead when inputs are mixed.

Start with the Credit Card Luhn Validator, plan repayments with the Credit Card Payoff Calculator, and check summaries with the Average Calculator.