What is the Luhn algorithm?

In short

The Luhn algorithm is a checksum formula that calculates the last digit of a card number from the digits before it, so that a mistyped number can be caught before it is sent anywhere. The Luhn algorithm detects every single wrong digit and most swaps of two neighbouring digits, and gives no protection against fraud.

Also called
Luhn check, Luhn formula, Mod 10, Modulus 10 check
Family
Cards
Facts checked

How the Luhn algorithm works

The check runs over the whole number, check digit included. For 4111 1111 1111 1111 the total is 30, so the number passes.

  • Start at the rightmost digit and move left
  • Double every second digit, beginning with the one next to the rightmost
  • Where doubling gives a two-digit result, subtract 9
  • Add up all the digits
  • The number is valid if the total is divisible by 10

Where the Luhn algorithm comes from

Hans Peter Luhn of IBM filed a patent for a device that computes such a check digit on 6 January 1954, and the patent was granted on 23 August 1960 as US 2,950,048. The formula is public and is used well beyond cards.

The card schemes rely on it. The Mastercard Rules of 2 June 2026 define a token as a value that passes the basic validation rules for a card number, including the Luhn formula for computing a modulus 10 check digit.

What the Luhn check does in a payments product

A payment form runs the check as the customer types, to catch a slip before an authorisation is attempted. Published test card numbers pass the check as well, which is why a form accepts them.

The check says nothing about whether a card exists, has funds or belongs to the person typing. Fraudsters generate valid numbers under a known BIN in bulk, which is the basis of a BIN attack, so the check is a convenience for honest customers and no part of fraud control.

Where the Luhn algorithm shows up in a platform

Modules that do the work

Platforms that need it

Where it is written

The laws and standards this page's facts come from.

General information, not legal advice: what applies to you depends on your services and your market.

Every term

Start your project

Tell us the idea. We'll show you the platform.

One call is enough to map your product to the modules that already exist.

  • Response in under one business day
  • NDA on request
  • No obligation
How can we help?