The last digit of a payment card number is not part of the account number. It is a checksum, calculated so that the number as a whole passes a test devised by IBM engineer Hans Peter Luhn, who filed the patent in 1954.

How it works

  1. Start from the rightmost digit and work left

    The rightmost digit is the check digit itself. Include it in the sum.

  2. Double every second digit

    That is the second from the right, the fourth, the sixth and so on.

  3. Subtract 9 from any doubled result above 9

    So 8 doubled is 16, which becomes 7. This is equivalent to adding the two digits together.

  4. Add everything up

    All the untouched digits plus all the adjusted doubled ones.

  5. Check it divides by 10

    If the total ends in zero, the number passes. If not, something was mistyped.

Test number:  4539 1488 0343 6467

Working from the right, double every second digit
(subtracting 9 from anything over 9):

  untouched   7  4  3  3  8  4  9  5   ->  43
  doubled     3  3  8  0  7  2  6  8   ->  37
                                           ---
  total                                     80

80 divides by 10  ->  the number is well-formed
A standard test card number, checked by hand

What it is for, and what it is not

The Luhn check exists to catch human error. In 1954 that meant numbers being read aloud, written down and keyed in by hand — a process that reliably produces two failure modes: a wrong digit, and two adjacent digits swapped. Luhn's formula catches both.

Why you still see it every day

When a checkout form tells you a card number is invalid before it appears to contact anyone, it has run the Luhn check locally. It costs nothing, it is instant, and it avoids sending an authorization request that was always going to fail.

That is why a mistyped card fails immediately and a genuinely declined card takes a moment — the first never left the browser.

The algorithm has outlived its original purpose considerably. It is now used for identification numbers well beyond payments, including some national identifiers and IMEI numbers on mobile phones.

Sources

  • Hans Peter Luhn, IBM — patent for a computer for verifying numbers, filed 1954, granted 1960.
  • ISO/IEC 7812, which specifies the structure of identification card numbers including the check digit.
  • The number above is a standard publicly published test value and corresponds to no real account.

GOOD QUESTIONS

Frequently asked

What is the Luhn algorithm?+

A checksum formula that validates identification numbers, including every payment card number. IBM engineer Hans Peter Luhn filed the patent in 1954. The last digit of a card number is chosen so that the whole number passes the check.

Does the Luhn check make card numbers secure?+

No, and it was never meant to. It catches typing mistakes — a mistyped digit or two transposed digits — before a request is sent. It offers no protection against fraud, because anyone can generate a number that passes.

Why do checkout forms reject a card before contacting the bank?+

Because they run the Luhn check locally first. It costs nothing, catches the most common input errors instantly, and avoids a pointless authorization request. That is why an obviously mistyped number fails faster than a genuinely declined one.

Can I check a card number by hand?+

Yes. Double every second digit from the right, subtract 9 from any result above 9, add all the digits together, and the total should divide by 10. It takes about thirty seconds.