Follow your curiosity

What discovery has been shared with you?

Start with one fact. Explore it, go deeper, then follow whichever branch catches your imagination.

Choose subjects for a surprise

Exploring any topic

Begin your discovery

Your next discovery is one click away.

Choose one or more subjects above, or leave Any Topic selected and let curiosity decide.

Technology

Why Modular Arithmetic Keeps Your Credit Card Safe

Quick fact

The last digit of most credit card numbers is a 'check digit' computed from the preceding digits using the Luhn algorithm. If you swap two digits or mistype one, the algorithm usually catches it, causing the transaction to be declined.

Why this is interesting

Your credit card number isn't just a random string of digits—it contains a hidden mathematical code that helps detect fraud before it happens. How does a simple calculation keep your money safe?

Read the full explanation

Understanding Why Modular Arithmetic Keeps Your Credit Card Safe

Think of a check digit as a built-in error detector. When you enter your credit card number online, the system doesn't instantly check against a database—it first performs a quick math test. This test, called the Luhn algorithm, uses modular arithmetic (specifically mod 10) to create a number that must match the final digit. Imagine a barcode: the last digit ensures the scanner read the previous numbers correctly. Similarly, your credit card's last digit is a mathematical fingerprint of all the digits before it. The algorithm works like this: starting from the rightmost digit (excluding the check digit), double every second digit. If doubling results in a number greater than 9, add the digits together (e.g., 16 becomes 1+6=7). Then sum all the resulting digits along with the undoubled digits. The check digit is the number that, when added to this sum, gives a multiple of 10. For example, if the sum is 47, the check digit is 3, because 47+3=50. When a card number is entered, the system performs this calculation and verifies that the final digit matches. It's a quick, efficient way to catch accidental typos and even some deliberate fraud attempts.

A deeper explanation

The power of modular arithmetic lies in its ability to detect changes: any single digit replacement or adjacent transposition changes the sum in a way that rarely results in another valid check digit. The Luhn algorithm is designed specifically to catch all single-digit errors and most adjacent transpositions. This is because operations in mod 10 arithmetic are sensitive to changes in the individual digits—unlike simple addition, which might be less affected by swapping, doubling every second digit ensures that a swap of adjacent digits often changes the total sum by an amount that isn't a multiple of 10, thus invalidating the number. In practice, this means that a fraudster cannot simply guess a valid card number; ~90% of random numbers fail the Luhn check. While this isn't a security measure against determined attackers (they could generate valid numbers using the algorithm), it serves as a crucial first-line check for data entry errors and casual fraud. It's also why many e-commerce sites instantly know when you've mistyped a digit. The Luhn algorithm is now embedded in global payment systems, and its use extends beyond credit cards to other identification numbers like some national ID numbers and retail loyalty cards.

Keep FACTREE close

Internet access is required. Updates arrive when you reopen or reload the app. You may need to sign in again in the installed app.