A credit card number must be from 13 to 16 digits long. The last
digit of the number is the check digit. That number is calculated from
an algorithm (called the
Luhn formula
or MOD 10) on the other numbers. This is to spot typos when a user
enters a number, and I assume was to allow detecting an error reading
the magnetic stripe when a card is swiped.
The MOD 10 check does not offer security, it offers error detection.
Think of it as fullfilling the same role as a CRC in software.
To calculate the check digit:
First drop the last digit from the card number (because that’s what we are trying to calculate)