Introduction
Major Industry Identifier
Issuer Identifier
Account Number
Check Digit
Examples
Java Source Code
This is not an essay on credit cards
per se. If that's what you're looking for, I recommend Joe Ziegler's
excellent series Everything
You Ever Wanted to Know about Credit Cards. This essay has a
narrower focus -- to explore the anatomy of your credit card number, and
to provide Java source code which determines if a given credit card
number might be valid.
Specifications for credit card
numbering have been drawn up by the International Standards Organization
(ISO/IEC 7812-1:1993) and the American National Standards Institute
(ANSI X4.13). These eminent organizations refuse to make their
publications freely available on-line, and so the following information
on the format of credit card numbers comes largely from an Internet
Engineering Task Force (IETF) draft by Donald E. Eastlake 3rd, "ISO
7812/7816 Numbers and the Domain Name System (DNS)"
(draft-eastlake-card-map-08, expires August 2001), available at the time
of this writing at http://www.globecom.net/ietf/draft/draft-eastlake-card-map-08.html.
I have not linked to this URL, because individual versions of IETF
drafts are notoriously ephemeral.
Digit numbering in this essay is left
to right. The "first" digit, therefore, means the leftmost
digit.
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.
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 |
34xxxx, 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.
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.).
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
Thanks to Aleksandar Janicijevic for
directing me to information about H.P. Luhn.
The most succint description of the
Luhn algorithm I have found comes from the hacker publication phrack
47-8: "For a card with an even number of digits, double every
odd numbered digit and subtract 9 if the product is greater than 9. Add
up all the even digits as well as the doubled-odd digits, and the result
must be a multiple of 10 or it's not a valid card. If the card has an
odd number of digits, perform the same addition doubling the even
numbered digits instead."
The bit about even and odd is a little
confusing. The main point is that you don't want to double the check
digit, and this can easily be done by starting with the check digit,
going backwards, and doubling every other digit. See the source
code below for details.
|