In the United States, they use the Luhn algorithm:
http://en.wikipedia.org/wiki/Luhn_algorithm
How the algorithm verifies a number:
- From the rightmost digit, which is the check digit, moving left, double the value of every second digit; if the product of this doubling operation is greater than 9 (e.g., 8 × 2 = 16), then sum the digits of the products (e.g., 16: 1 + 6 = 7, 18: 1 + 8 = 9).
- Take the sum of all the digits.
- If the total modulo 10 is equal to 0 (if the total ends in zero) then the number is valid according to the Luhn formula; else it is not valid.
How to calculate the check digit:
The check digit is obtained by computing the sum of digits then computing 9 times that value modulo 10. In algorithm form:
- Compute the sum of the digits (after doubling every second digit).
- Multiply by 9.
- The last digit is the check digit.
Example:
Number: 4321-5678-7531-456x
(where x
is the check digit).
1. Number: 4 3 2 1 5 6 7 8 7 5 3 1 4 5 6 X
2. Double every second: 8 4 10 14 14 6 8 12
3. Sum digits >9: 8 3 4 1 1 6 5 8 5 5 6 1 8 5 3
4. Sum all digits: 8 + 3 + 4 + 1 + 1 + 6 + 5 + 8 + 5 + 5 + 6 + 1 + 8 + 5 + 3 = 69
5. Multiply sum by 9: 69 x 9 = 621
6. Take value mod 10: 621 mod 10 = 1 => x = 1
The check digit is 1
and the comnplete valid number is 4321-5678-7531-4561
.
If you were to run through the algorithm again to verify the number, then the sum of all digits in Step 4 would be 69 + 1 = 70
. Then, 70 mod 10 = 0
, so the number is valid according to the algorithm.