Credit Card Algo!!

It featured around E-mails long time back. Well thought, let me not let it fade away in the huge permutations of 1s and 0s. so just packing this cute litil algo on this page to stay ever accessible…


Does this Pic give u indication of money.. cash… There is something very interesting (let alone the cash aspect of the card) about the number pattern in the card. Well Dont worry we are no way close to number thory or something like that. Also knowing this can noway help u tweak card numbers for your use . But then this credit card funda is quite interesting.

The length of a credit card can be either 13 or 15 or 16 characters. The first digit is called the MIF or the major industry identifier. The various values are as follows…


ISO/TC 68 and Other Industries




Airlines and Other Industries


Travel and Entertainment


Banking and Financial


Banking and Financial


Merchandizing and Banking




Telecommunications and Other Industries


National ( Local Use )

Most of us will carry credit cards beginning with 4 or 5. A petrol card will begin with 7. The first 4 to 6 digits are called the issuers code and they tell us which entity issued us the card. Some well known issuers are as.

Issuer's Code
The first four digits

Card Issuer

of Digits

3000 to 3059
3600 to 3699
3800 to 3889

Diners Club


3400 to 3499
3700 to 3799

American Express


3528 to 3589



3890 to 3899

Carte Blanche


4000 to 4999


13 or 16

5100 to 5599




Australian BankCard



Discover / Novus



The remaining 10-12 bits are the actual credit card number. These numbers are not just randomly generated by the credit card companies but are generated such that they meet a certain rule. This rule or algorithm called the Luhn algorithm. The International Standards Organization (ISO/IEC 7812-1:1993) and the American National Standards Institute (ANSI X4.13) have now standardized on the above algorithm for credit card number validation.

Lets take a dummy Visa card and apply the Luhn algorithm to it.

4567 1234 5678 9129

We first start from the right and this last digit is called the check sum. We start with the rightmost –1 digit and multiply every other digit by 2.

4 5 6 7 1 2 3 4 5 6 7 8 9 1 2 9

8 12 2 6 10 14 18 4

We then subtract 9 from any number larger than 10. Thus we get.

8 3 2 6 1 5 9 4.

Another way out is by adding the individual digits.

We then add them all up to get


We then add all the other digits to get


The sum of the two is 80 which will add up to a number divisible by 10. Thus the above algorithm is called the Luhn modulus 10. The last digit is called the check digit as it is the one used to make sure that we get a final number divisible by 10. We have a 90% reliability with the Luhn algorithm. Next time you look at your credit card number don just look at it like a strange combiination of numbers but just note the pattern that it satisfies..


10 thoughts on “Credit Card Algo!!

  1. can u b a bit clear!! i din get what u are asking for.. if u are asking for a code to check if a number satisfies the Credit card number criteria then fine.. i think i have it somewhere…

  2. heh, real nice writeup, i guess the real algo somebody would want is the 2nd part of track2, so cc# = xxxxx, the xxxx part is also a mathemtical algorithm for each instituion???

  3. I would like to know what are the steps in making a track2 algoritm. Is there an universal algorithm for track2 (like Luhn formula )?

  4. hello sir,
    we are using tsop as ir receiver, we are having problem with the circuit,since tsop output is active low we are connecting it to 7414 then its output to uln2003 driver and an led at the output of uln2003, we are also connecting a capacitor of 47 micro farad between tsop gnd and vcc pin does this circuit works…..waitin for ur reply

    thanking you,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s