How does this work?
This method is called the Luhn algorithm, here is a demonstration of how
it works.
First, take all the digits of your credit card, and double every second
digit from the right. If the digit is above 9, then you subtract 9 from
it.
Digits of your card:
6183842264819971
Every second digit from your card, doubled, starting from the right and
subtracted by 9 if it's over 9:
3173744234719951
Take the sum of every digit, even the unchanged ones:
70
If the number is divisable by 10, then it's valid, otherwise it is
invalid.