http://www.creditcardanswers.co.uk/digit-algorithm-credit-card-codes-explained.htmleasy really
Credit Card Codes Explained
Credit Cards Credit Card Algorithm 16
You may not pay much attention to the 16 digit number on the front of your credit card, but it is by far the most important part of your plastic. Furthermore, the sequence of numbers is absolutely unique, separating you from the millions, or possibly billions of other credit card users in the world. The numbers found on credit cards have a certain amount of internal structure, and share a common numbering scheme. Credit card numbers are a special case of ISO 7812 numbers, which are numbers that contain a single-digit major industry identifier (MII), a six-digit issuer identifier number (IIN), an account number, and a single digit checksum using the Luhn algorithm.
The Luhn Algorithm
The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers and Canadian Social Insurance Numbers. It was created by IBM scientist Hans Peter Luhn and described in U.S. in 1954.
The algorithm is in the public domain and is in wide use today. It is not intended to be a cryptographically secure hash function. It was designed to protect against accidental errors, not malicious attacks. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from collections of random digits.
Your Card Prefix
The credit card number's prefix is the sequence of digits at the beginning of the number that determine the credit card network to which the number belongs. The first six digits of the credit card number are known as the Bank Identification Number (BIN). These identify the institution that issued the card to the card holder. The rest of the number is allocated by the issuer.
Online merchants may use BIN lookups to help validate transactions. For example, if the credit card's BIN indicates a bank in one country, while the customer's billing address is in another, the transaction may call for extra scrutiny.