Generated by Codex with GPT 5.6 Sol XHigh
A Number That Checks Itself
A credit card number is more than an account label. Its digits follow a compact error-detection scheme that lets a checkout form reject many typing mistakes before contacting a bank. The scheme is the Luhn algorithm, named for IBM researcher Hans Peter Luhn, who patented it in 1960. Variants of the same idea also protect barcodes, package-tracking numbers, bank-account identifiers and ISBNs.
The number on a card has several jobs. Its first digit identifies a broad industry category: Visa numbers begin with 4, for example, while Discover numbers begin with 6. The next five to seven digits identify the issuing institution, and most of the remaining digits specify the account. The last digit serves a different purpose. Known as the check digit, it is chosen so that the complete number passes the Luhn test.
To perform the test, the check digit is first set aside. Starting from the right of the remaining number, every other digit is doubled. The digits of all the resulting values are then added individually, so a doubled 7 becomes 14 and contributes 1 + 4, or 5. Finally, the check digit is added. A validly structured number must produce a total divisible by 10.
The article demonstrates the process with a deliberately mistyped sample card number. Its transformed digits add to 67, and its displayed check digit raises the total to 75. Because 75 is not a multiple of 10, the number cannot be valid under the algorithm. Changing the final digit to 3 would instead produce 70 and satisfy the test. In normal use, an issuer assigns the account portion first and then calculates the check digit needed to reach the next multiple of 10.
Why Common Mistakes Stand Out
The algorithm’s usefulness comes from the way each input digit contributes exactly one digit to the total. A digit in an undoubled position contributes its ordinary value. In a doubled position, the possible contributions for inputs zero through nine are 0, 2, 4, 6, 8, 1, 3, 5, 7 and 9. Each value in either list is unique. Replacing any one digit therefore changes the sum by an amount that is not a multiple of 10, so the altered number fails the test.
Luhn also detects nearly every swap of neighboring digits because adjacent positions receive different treatments: one is doubled and the other is not. The article illustrates this with the pair 31. In the correct order, with 3 doubled, the pair contributes 6 + 1 = 7. Reversing it to 13 makes the pair contribute 2 + 3 = 5, changing the total and exposing the error. The exception is a swap between 09 and 90, which contributes the same amount in either order.
That small gap motivated Dutch mathematician Jacobus Verhoeff to devise a stronger check-digit system in 1969. Verhoeff reported that single-digit substitutions and adjacent transpositions account for nearly 90 percent of human input errors. His algorithm catches those mistakes, including the 09/90 case, as well as rarer patterns. It never became as widespread, perhaps because it is more complex and arrived after Luhn’s simpler method had already proved good enough for routine use.
A Fast Filter, Not Proof of Payment
Passing the Luhn test does not prove that a card number exists, belongs to the buyer or has funds available. Many invented numbers can satisfy the checksum, and a knowledgeable fraudster can construct one easily. Failure has a firmer meaning: the number is malformed and does not need to be sent any farther.
That asymmetry makes the algorithm an efficient first line of defense. A merchant eventually has to send card details to a specialized service for authentication and payment processing, but that communication takes time and costs money. Running the Luhn calculation locally requires almost no computing power and filters out ordinary typing errors before they trigger an unnecessary request. More sophisticated validation remains responsible for the cases the checksum cannot settle.
The broader lesson is that a small amount of mathematical structure can make an identifier partly self-checking. One carefully chosen digit cannot establish authenticity, but it can turn the most common human slips into visible violations of a simple rule. The next time a checkout page rejects a number immediately, it may be doing less networking than arithmetic.