Understanding the Luhn Algorithm - How Credit Card Numbers are Made

*Editorial Note: This content is not provided or commissioned by the credit card issuer. Any opinions, analyses, reviews or recommendations expressed in this article are those of the author’s alone, and have not been reviewed, approved or otherwise endorsed by the credit card issuer. This site may be compensated through the credit card issuer Affiliate Program.

This post contains references to products from one or more of our advertisers. We may receive compensation when you click on product links. For more information, please see our Advertiser Disclosure

Imagine what power you’d have if you knew how credit card numbers are generated to make them legitimate and functional. You could launch a global business manufacturing counterfeit cards (illegal of course) similar to creating counterfeit currency.  The problem of course is figuring out what numbers to create, and the Luhn algorithm makes certain that your business idea is destined to fail.

Introducing the Luhn Algorithm

I certainly don’t want some kid in a basement to cook up a card with my credit card account numbers on it and then go on a spree at the mall. The reason someone has not been able to pull off that kind of get-rich-quick scheme is because of something known as the Luhn algorithm. This is a mathematical formula that when applied generates credit card numbers that are genuinely unique and virtually impossible to duplicate, guess, or otherwise invent.

Hans Luhn was an IBM employee who, back in the 1950s, came up with an algorithm to verify a string of unique numbers. Today his method – known as the Luhn algorithm – is used by all credit card companies as a way to create distinct card account numbers. That way there is no possibility, for example, that your card number will turn out to be the same as mine. That would create chaos, naturally, while also giving criminals a way to exploit the entire credit card account numbering system.

Why the Algorithm is So Vital

In this era when plastic represents more than just convenience, there is a serious need for the protection of credit card numbers. Credit card numbers have been a target of choice for many thieves and hackers. One of my card numbers was stolen once and used to pay for travel all over California and Nevada. Meanwhile I was traveling across England and France. Since I have not figured out how to clone myself the itineraries looked rather suspicious on my monthly statement. So the Luhn algorithm is in many ways the Holy Grail of passwords. It cannot save you from losing your card or having someone working in a restaurant copy it down and use it to buy stuff. But it can guard the numbers in way that allows each of us to have our own personal and private account.

Applying the Luhn algorithm can be a time-intensive process but it breaks down to a few simple steps.  Grab any credit card from your wallet, start with the second digit from the right and follow the instructions below:

If your final number is divisible by ten, congratulations, you have a real credit card. If it's not, you best double check your math because it should be.

Most credit card numbers start with six digits that identify the card issuing company. Then there are 10 digits more that can be arranged in ten billion different combinations. If the last one in the sequence does not compute correctly after applying the Luhn algorithm to the preceding digits then the card number is a fake and will not work. So one company can safely and securely issue about one billion individual cards using the algorithm.

The Challenge of Cracking the Code

The formula has held up to the test of time and the pressures of the underworld. Despite tens of millions of attempts by hundreds of thousands of professional hackers, it remains the gatekeeper for the entire credit card industry. Without it you would not be able to securely use your card and the convenient world of plastic as we know it would experience a mega-meltdown.

Recommended Posts:

Having Trouble Choosing a Credit Card?

Sign up to receive a copy of our free ebook, The Ultimate Guide to Credit Cards. It will help you pick the perfect card!

Easily see your credit score in seconds.
Concierge icon Learn More
Concierge screenshot on mobile device Concierge screenshot on laptop device
CompareCards icon
Join Our Newsletter
Please enter a valid email address.
Thanks for signing up!
Ask Our Credit Experts Submit questions to our credit experts.
Thank you, we’ve received your question. Look for the response in your inbox in the next few days and subscribe to our newsletter.
Error sample
Most Popular Posts
CompareCards ad