Prøve GULL - Gratis

The Math Trick Hiding in Credit Card Numbers

Scientific American

|

November 2025

This simple algorithm from the 1960s catches your typos

YOU’RE AT THE CHECKOUT SCREEN after an online shopping spree, ready to enter your credit card number. You type it in and instantly see a red error message: “Please enter a valid credit card number.” Annoyed, you scan back through each digit and spot the culprit: you put a 6 where a 5 belonged. Typo corrected; purchase complete. But how did the website detect your error so quickly? Does the online platform keep a master list of every valid credit card number to compare your entry against? Did it ping your bank in a split second? The explanation is much cleverer.

All mainstream credit card numbers employ a mathematical trick designed to catch the most common typos. It’s called the Luhn algorithm, named after IBM researcher Hans Peter Luhn, who patented it in 1960. Similar error-checking schemes lurk in many of the numbers you encounter daily: barcodes, package tracking numbers, bank account numbers and even ISBNs on books.

Grab a credit card from your wallet, and you'll find it contains more structure than first glance suggests. The anatomy of a credit card number includes four main parts. To demonstrate, I'll use my personal Visa.

The first digit is the major industry identifier. Visa cards always begin with a 4, and Discover cards always start with a 6. The next five to seven digits pinpoint the bank or institution that issued the card. What remains (sans the final digit) is your specific account number at that bank. The final digit, sometimes called the check digit, has nothing to do with financial institutions. Issuers tack it on so the entire card number will pass a specific mathematical test—the Luhn algorithm. Here’s how the algorithm works:

1. Write out all but the last digit of the card number.

2. Starting from the right, double every other number.

3. Sum all the resulting digits (not numbers). For example, if you doubled a 7 to a 14 in step 2, it would become 1+4=5 in this step.

FLERE HISTORIER FRA Scientific American

Scientific American

Scientific American

METEORITE HEIST

Violence, lies and the smuggling of the ninth-largest meteorite in the world

time to read

13 mins

November 2025

Scientific American

Scientific American

Workouts Help to Treat Cancer

Exercise improves survival, limits recurrence, and can be used with surgery and drugs

time to read

3 mins

November 2025

Scientific American

Scientific American

LIFE'S BIG BANGS

Controversial evidence hints that complex life might have emerged hundreds of millions of years earlier than previously thought—and possibly more than once

time to read

17 mins

November 2025

Scientific American

Scientific American

Canyon Wonderland

An underwater robot documents the strange denizens of Mar del Plata Canyon

time to read

2 mins

November 2025

Scientific American

The Math Trick Hiding in Credit Card Numbers

This simple algorithm from the 1960s catches your typos

time to read

4 mins

November 2025

Scientific American

Scientific American

50, 100 & 150 Years

\"A comprehensive study by the Jet Propulsion Laboratory vigorously urges that a $1-billion program be launched to develop a new automobile engine for introduction by 1985 or sooner.

time to read

3 mins

November 2025

Scientific American

Scientific American

Grippy Super Team

Ants form complex chains to carry more than 100 times each ant's weight

time to read

2 mins

November 2025

Scientific American

Human on a Bicycle

Revisiting a classic graphic on the efficiency of motion

time to read

1 min

November 2025

Scientific American

Scientific American

Risky Genes

As genetic risk scores get integrated into clinical care, experts expect patients to gain earlier access to therapies and enjoy better outcomes

time to read

9 mins

November 2025

Scientific American

Scientific American

Gut Virome

Your digestive tract is crawling with viruses— and that's a good thing

time to read

2 mins

November 2025

Listen

Translate

Share

-
+

Change font size