Real World Maths Busters

The Maths Behind Everyday Life

The story, the formula and a worked example — see exactly where this maths shows up in the world around you.

Back to all stories
Technology 3 min read

The algorithm that validates every credit card number

A quick doubling-and-summing trick spots a mistyped card number instantly.

Before a payment even reaches the bank, the Luhn algorithm checks the card number for typos. Double every second digit, add everything up, and a valid number is always a multiple of 10.

Double, sum, check divisibility

Double every second digit from the right (subtract 9 if over 9), add all digits, and the total must be divisible by 10.

S mod 10=0S \bmod 10 = 0

Valid Luhn number

Testing a number

Suppose the Luhn sum comes to 70.

Is it valid?

  1. 1

    Take the total mod 10

    70 mod 10=070 \bmod 10 = 0
  2. 2

    Verdict

    Divisible by 10, so it passes the Luhn check — a single typo would have made it non-zero.

Answer

A valid card number's Luhn sum ends in 0; typos almost always fail.

The formula behind it

Luhn Check

S mod 10=0S \bmod 10 = 0

The takeaway

The Luhn checksum catches most mistyped card numbers instantly by requiring the doubled-and-summed digits to be divisible by 10.

Back to all stories