CHOPGO.COM eShop - Secret of your Credit Card Number - Luhn formula
CHOPGO.COM eShop

The Secret of Your Credit Card Number


Major Industry Identifier

The first digit of your credit card number is the Major Industry Identifier (MII), which represents the category of entity which issued your credit card. Different MII digits represent the following issuer categories:

MII Digit Value Issuer Category
0 ISO/TC 68 and other industry assignments
1 Airlines
2 Airlines and other industry assignments
3 Travel and entertainment
4 Banking and financial
5 Banking and financial
6 Merchandizing and banking
7 Petroleum
8 Telecommunications and other industry assignments
9 National assignment

For example, American Express, Diner's Club, and Carte Blanche are in the travel and entertainment category, VISA, MasterCard, and Discover are in the banking and financial category, and SUN Oil and Exxon are in the petroleum category.

Issuer Identifier

The first 6 digits of your credit card number (including the initial MII digit) form the issuer identifier. This means that the total number of possible issuers is a million (10 raised to the sixth power, or 1,000,000).

Some of the better known issuer identifiers are listed in the following table:

Issuer Identifier Card Number Length
Diner's Club/Carte Blanche 300xxx-305xxx,
36xxxx, 38xxxx
14
American Express 33xxxx, 37xxxx 15
VISA 4xxxxx 13, 16
MasterCard 51xxxx-55xxxx 16
Discover 6011xx 16

If the MII digit is 9, then the next three digits of the issuer identifier are the 3-digit country codes defined in ISO 3166, and the remaining final two digits of the issuer identifier can be defined by the national standards body of the specified country in whatever way it wishes.

Account Number

Digits 7 to (n - 1) of your credit card number are your individual account identifier. The maximum length of a credit card number is 19 digits. Since the initial 6 digits of a credit card number are the issuer identifier, and the final digit is the check digit, this means that the maximum length of the account number field is 19 - 7, or 12 digits. Each issuer therefore has a trillion (10 raised to the 12th power, or 1,000,000,000,000) possible account numbers.

If we consider the large number of potential customers and usurious interest rates charged by issuers, there is obviously a lot of money to be made in the credit card industry. In more civilized ages, people believed that usury was a grievous offense contrary to nature or a mortal sin, not an acceptable business practice (Aristotle, Politics 1.10; St. Thomas Aquinas, De Malo 13.4; Dante, Inferno 11.94-111; etc.).

Check Digit

The final digit of your credit card number is a check digit, akin to a checksum. The algorithm used to arrive at the proper check digit is called the Luhn algorithm, after IBM scientist Hans Peter Luhn (1896-1964), who was awarded US Patent 2950048 ("Computer for Verifying Numbers") for the technique in 1960. For details about Luhn's life, see



Luhn formula


Based on ANSI X4.13, the LUHN formula (also known as the modulus 10 -- or mod 10 -- algorithm ) is used to generate and/or validate and verify the accuracy of credit-card numbers. Most credit cards contain a check digit, which is the digit at the end of the credit card number. The first part of the credit-card number identifies the type of credit card (Visa, MasterCard, American Express, etc.), and the middle digits identify the bank and customer.

To generate the check digit, the LUHN formula is applied to the number. To validate the credit-card number, the check digit is figured into the formula.

Here's how the algorithm works for verifying credit cards; the math is quite simple:

1) Starting with the second to last digit and moving left, double the value of all the alternating digits.
2) Starting from the left, take all the unaffected digits and add them to the results of all the individual digits from step 1. If the results from any of the numbers from step 1 are double digits, make sure to add the two numbers first (i.e. 18 would yield 1+8). Basically, your equation will look like a regular addition problem that adds every single digit.
3) The total from step 2 must end in zero for the credit-card number to be valid. The LUHN formula was created in the late 1960s by a group of mathematicians. Shortly thereafter, credit card companies adopted it. Because the algorithm is in the public domain, it can be used by anyone.

The LUHN formula is also used to check Canadian Social Insurance Number (SIN) validity. In fact, the LUHN formula is widely used to generate the check digits of many different primary account numbers. Almost all institutions that create and require unique account or identification numbers use the Mod 10 algorithm.

The Luhn algorithm (also known as the mod 10 algorithm) is used to catch data entry errors when entering long sequences of numbers. It will catch most errors, especially common ones, such as accidentally tranposing two adjacent numbers. All credit card numbers and Canadian social insurance numvers are generated by the Luhn algorithm to prevent them from being entered incorrectly.

 
 

The algorithm, take one

Most resources on the Web describe the Luhn algorithm for verifying a number has been correctly entered im the following manner.

Let's start with a number that we want to test:

5 1 2 8 9 6 0 1 2 8 1

Starting with the second-rightmost digit and working from right to left, double every other digit. If we take the example number provided above, the digits become:

5 2 2 16 9 12 0 2 2 16 1

For any digit that was turned into a two-digit number as a result of the previous step, turn it into a single-digit number by adding its digits together.

In our example number, the second-last digit of the original number was 8 and got doubled to become 16. We turn it into a single-digit number by adding its two digits, 1 and 6, to make 7.

Our example number becomes:

5 2 2 7 9 3 0 2 2 7 1

Add the resulting digits together. If the result is a multiple of 10 (put another way, if it has no remainder if divided by 10), then the number is valid.

Once again, referring to the result of the previous step with our example number:

5 + 2 + 2 + 7 + 9 + 3 + 0 + 2 + 2 + 7 + 1 = 40

40 mod 10 = 0

The example number is valid.

 
 

The algorithm, take two

The algorithm, as described above, is easy for a person to follow. However, it's not the most efficient way of doing it. You'd need to iterate twice through the sequence: first backwards, starting at the second-last digit and only for every other digit, then forwards through every digit. If we could reduce the algorithm so that you only needed to iterate through the sequence once and if that iteration could start at the beginning of the sequence and go forwards, the code would be much simpler.

It turns out that it is possible to simplify the algorithm this way. It turns out that if the sequence has an even-numbered length, you double the digits in the even-numbered positions (assuming that the first position is 0, not 1). If the sequence has an odd-numbered length, you double the digits in the odd-numbered positions (once again, assuming the first position is 0).

The rule for doubling digits is the same as with the first version of the algorithm: if the result is a two-digit number, add those two digits together. In the case where we're adding single-digit numbers together, an equivalent operation would be: if the result is greater than 9, subtract 9 from that result.

The algorithm then becomes...

Start with a checksum of 0. Make a note of which digits are to be doubled. If the sequence length is odd, the digits in odd-numbered positions are the ones to be doubled. If the sequence is even, the digits in the even-numbered positions will be doubled. The first position is position 0.

For each digit in the sequence:

If this digit is to be doubled, double it to get a result value. If the result value is greater than 9, subtract 9 from it.

If the digit is not to be doubled, the result value is the value of the digit.

Add the result value to the checksum.

If the checksum is evenly divisble by 10, the number is valid; otherwise, it isn't.

Sample credit card number:

VISA: 4417123456789113

Note: The VISA number above is strictly a result of calculation using the Luhn formula, it is by no mean a copy from an existing credit card.


Home | Knowledge Base | Registration

Copyright ©2004 Logic Century Inc. All rights reserved.