How the Luhn algorithm works
The Luhn algorithm, patented by IBM engineer Hans Peter Luhn in 1960 and now specified in ISO/IEC 7812-1, adds one check digit to the end of a number so that simple typing mistakes can be caught without contacting a server.
To validate a number: start at the rightmost digit (the check digit) and move left. Leave the check digit alone, double the next digit, leave the one after that, and keep alternating. When a doubled digit is 10 or more, subtract 9 (for example 8 doubled is 16, and 16 minus 9 is 7; that is the same as adding 1 and 6). Add everything up. The number is valid when the total is a multiple of 10.
To compute a check digit: run the same process on the payload, but double the rightmost payload digit first, because it will sit next to the check digit once appended. The check digit is (10 − (sum mod 10)) mod 10.
Worked example: for 7992739871 the weighted sum is 67, so the check digit is (10 − 7) mod 10 = 3, and the full number 79927398713 sums to 70.