Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    The Mission review – a surgeon saves lives in war-torn Gaza in a visceral portrait of human endurance | Movies

    Whereabouts of nearly 300 people with Ebola unknown in DR Congo | Global development

    Nigel Farage’s anti-WHO campaign moves to US with allies added to board | Nigel Farage

    Facebook X (Twitter) Instagram
    Facebook X (Twitter) YouTube LinkedIn
    Naija Global News |
    Sunday, June 28
    • Business
    • Health
    • Politics
    • Science
    • Sports
    • Education
    • Social Issues
    • Technology
    • More
      • Crime & Justice
      • Environment
      • Entertainment
    Naija Global News |
    You are at:Home»Environment»What Is the Luhn Algorithm? The Math Behind Secure Credit Card Numbers
    Environment

    What Is the Luhn Algorithm? The Math Behind Secure Credit Card Numbers

    onlyplanz_80y6mtBy onlyplanz_80y6mtAugust 13, 2025006 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Email
    What Is the Luhn Algorithm? The Math Behind Secure Credit Card Numbers

    Isabel Pavia/Getty Images

    Share
    Facebook Twitter LinkedIn Pinterest Email

    August 12, 2025

    5 min read

    The Math Trick Hidden in Your Credit Card Number

    Find out how this simple algorithm from the 1960s keeps your wallet safe

    By Jack Murtagh edited by Jeanna Bryner

    Isabel Pavia/Getty Images

    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 tapped the 6 key 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 obey 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. [Stretch your math muscles with these puzzles]

    On supporting science journalism

    If you’re enjoying this article, consider supporting our award-winning journalism by subscribing. By purchasing a subscription you are helping to ensure the future of impactful stories about the discoveries and ideas shaping our world today.

    The first digit is the major industry identifier. Visas always begin with a 4, and Discovers 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 within that bank. The final digit, sometimes called the “check digit,” has nothing to do with financial institutions. Issuers tack it on so that the whole card number will satisfy 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. Double every other number starting at the right.

    3. Sum the resulting digits (not numbers). E.g., if you doubled a 7 to become a 14 in Step 2, this will become 1 + 4 = 5 in this step.

    4. Add the check digit to the sum. If the result is not a multiple of 10, then the credit card number is invalid.

    I’ll show the Luhn algorithm in action on my Visa, but you should try it with your credit card, too.

    The number crunching culminates in 75, which is not a multiple of 10. So this cannot be my real credit card number; I must have mistyped it.

    Credit card issuers first assign the account numbers and then compute steps one through three of the Luhn algorithm to determine the appropriate check digit. In this case, the card number should have ended in a 3 because 67 + 3 = 70, a multiple of 10.

    This particular dance of digits has come to dominate credit card verification because of its simplicity and powerful set of features. If you mess up any single digit when entering your card number, the Luhn algorithm will detect it. If you accidentally swap adjacent card digits while inputting, it will detect that, too (with the one exception of flipping 09 to 90, or vice versa).

    Dutch mathematician Jacobus Verhoeff reported in 1969 that two errors—mistyping a single digit and swapping two neighboring digits of one’s card number—account for nearly 90 percent of all human input errors in practice. Verhoeff developed an even more comprehensive algorithm that, in addition to detecting all of the same typos as Luhn’s algorithm, also catches 09/90 transpositions, as well as more exotic slipups. Verhoeff’s algorithm was a mathematical triumph. Some contemporaries had even published false proofs claiming that no single check digit could carry enough information to catch all of these errors. Verhoeff’s algorithm never gained widespread adoption, however, perhaps because of its increased complexity over Luhn’s or because Luhn’s algorithm was already deployed and did a sufficient job.

    Luhn’s algorithm saves you time and businesses money. At some point during a purchase, a vendor will verify that your card belongs to you by sending your information to a specialized card-validation service. This communication takes time and incurs processing fees for the business. It would be a waste of seconds and cents to outsource needless back-and-forth with a professional validation service to catch common typos. Because Luhn’s algorithm requires so little processing power, the computer handling the transaction can also run the check without needing to contact any third party.

    Importantly, passing Luhn’s algorithm does not guarantee a valid credit card number. Rather failing it guarantees an invalid credit card number. The algorithm puts up a first line of defense that less common typos and savvy fraudsters can slip through. Those cases get caught by the more resource-intensive card-validation services.

    How does Luhn’s algorithm know when your fingers fumble? Every digit in a credit card number contributes a one-digit number to the final sum in the algorithm. If the digit sits in a position that does not get doubled, then it just contributes itself to the sum. But even if a digit sits in a doubled position, summing the individual digits of the resulting two-digit number always yields a one-digit number again. The table below lists all of these possible contributions:

    For example, 6 contributes 6 when it’s in an undoubled position, and it contributes 3 from a doubled position because 6 doubled equals 12 and 1 + 2 = 3. Messing up a single number while typing your credit card effectively shifts you up or down within the same column of this table and alters one term in the algorithm’s sum. By design, a valid credit card number results in a sum that is a multiple of 10. Any single-digit error will change the sum by a one-digit number, so the mistaken sum will definitely not be a multiple of 10.

    Formally proving that Luhn’s algorithm detects swapping adjacent digits involves some case analysis, but an example will help illustrate the idea. Imagine we have the sequence 31 in our credit card, with the 3 in a doubled position. We accidentally enter 13 instead. In the correct sum, this duo contributes 6 + 1 = 7 (3 doubled plus 1 undoubled), whereas in the faulty sum, it contributes 2 + 3 = 5 (1 doubled plus 3 undoubled). So the error ultimately changes our sum by 2: going from a contribution of 7 to a contribution of 5. If the original sum yielded a multiple of 10, then there’s no way this new one will. We can check that this works for every pair of numbers except for 09/90, which both contribute the same quantity to the Luhn sum.

    Next time a checkout page flashes that annoying error message, remember: a simple piece of math under the hood just saved a little time and money for everyone involved.

    algorithm card Credit Luhn Math numbers secure
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticlePatients like a medic in a white coat, but often mistake female doctors for nurses | Doctors
    Next Article How a Jamaican student invented a self-disinfecting door handle for hospitals: ‘Design that fits reality’ | Jamaica
    onlyplanz_80y6mt
    • Website

    Related Posts

    Why America is failing its health report card | Robert B Shpiner

    May 30, 2026

    End of Trump tariffs on whisky sparks row between Scottish parties over claiming credit | Scottish politics

    May 2, 2026

    Private credit group Ares draws nearly $20bn from investors

    May 1, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    The science influencers going viral on TikTok to fight misinformation

    February 17, 20262 Views

    Watch Lady Gaga’s Perform ‘Vanish Into You’ on ‘Colbert’

    September 9, 20251 Views

    Advertisers flock to Fox seeking an ‘audience of one’ — Donald Trump

    July 13, 20251 Views
    Stay In Touch
    • Facebook
    • YouTube
    • TikTok
    • WhatsApp
    • Twitter
    • Instagram
    Latest Reviews

    At Chile’s Vera Rubin Observatory, Earth’s Largest Camera Surveys the Sky

    By onlyplanz_80y6mtJune 19, 2025

    SpaceX Starship Explodes Before Test Fire

    By onlyplanz_80y6mtJune 19, 2025

    How the L.A. Port got hit by Trump’s Tariffs

    By onlyplanz_80y6mtJune 19, 2025

    Subscribe to Updates

    Get the latest tech news from FooBar about tech, design and biz.

    Most Popular

    The science influencers going viral on TikTok to fight misinformation

    February 17, 20262 Views

    Watch Lady Gaga’s Perform ‘Vanish Into You’ on ‘Colbert’

    September 9, 20251 Views

    Advertisers flock to Fox seeking an ‘audience of one’ — Donald Trump

    July 13, 20251 Views
    Our Picks

    The Mission review – a surgeon saves lives in war-torn Gaza in a visceral portrait of human endurance | Movies

    Whereabouts of nearly 300 people with Ebola unknown in DR Congo | Global development

    Nigel Farage’s anti-WHO campaign moves to US with allies added to board | Nigel Farage

    Recent Posts
    • The Mission review – a surgeon saves lives in war-torn Gaza in a visceral portrait of human endurance | Movies
    • Whereabouts of nearly 300 people with Ebola unknown in DR Congo | Global development
    • Nigel Farage’s anti-WHO campaign moves to US with allies added to board | Nigel Farage
    • Here’s what to do if your StubHub World Cup resale ticket is canceled | World Cup 2026
    • ‘A sad inevitability’: after decades of climate warnings, why is Europe so unprepared for rising heat? | Extreme heat
    © 2026 naijaglobalnews. Designed by Pro.
    • About Us
    • Disclaimer
    • Get In Touch
    • Privacy Policy
    • Terms and Conditions

    Type above and press Enter to search. Press Esc to cancel.