Hmm, well, it's tricky to explain!
First, check out the Wikipedia article on the algorithm itself:
https://en.wikipedia.org/wiki/Luhn_algorithm
Next, consider this sheet:
Excel 2012
| A | B | C | D | E |
---|
79927398713 | Digit | Digit * 1 result | Digit * 2 result | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: right"]TRUE[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"]TRUE[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]4[/TD]
[TD="align: center"]5[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]5[/TD]
[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]8[/TD]
[TD="align: center"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]1[/TD]
[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]3[/TD]
[TD="align: center"]9[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]5[/TD]
[TD="align: center"]10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]7[/TD]
[TD="align: center"]11[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]9[/TD]
</tbody>
Sheet8
[TABLE="width: 85%"]
<tbody>[TR]
[TD]
Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]B1[/TH]
[TD="align: left"]=MOD(
SUM(IF(MID(TEXT(INT(A1/10),REPT("0",15)),{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},1)="9",9,MOD(MID(TEXT(INT(A1/10),REPT("0",15)),{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},1)*{2,1,2,1,2,1,2,1,2,1,2,1,2,1,2},9)))+RIGHT(A1),10)=0[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]B2[/TH]
[TD="align: left"]=MOD(
SUM(CHOOSE(MID(TEXT(INT(A1/10),REPT("0",15)),{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},1)+{11,1,11,1,11,1,11,1,11,1,11,1,11,1,11},0,1,2,3,4,5,6,7,8,9,0,2,4,6,8,1,3,5,7,9))+RIGHT(A1),10)=0[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
First, I noticed that I had an unnecessary MOD in the original formula, so I removed it. Next, I figured out a shorter and probably easier to explain formula in B2. So I'll explain that, and if you're interested, you can try to deconstruct the original.
OK, adding preceding zeros does not affect the end result, but it does make it easy to decide whether each individual digit should be multiplied by 1 or 2. So I first use INT(A1/10) to remove the last (check) digit, then I use TEXT to append as many preceding zeros are needed to make it 15 digits long. Next, I use MID(#,{1,2,3,...},1) to split the number into individual digits. This makes it an array formula, but when Excel sees the explicit array constant, you don't need to add the Control+Shift+Enter.
Now look at the table in C1:E11. This shows the values that are added to the overall sum for each digit, depending on whether we multiply by 1 or 2. Note that E7 is 1, because 5*2=10, and 1+0=1, according to the algorithm. So if we have this list hardcoded in the formula, all we need to do is figure out the position in the list. When we multiply by 1, we just need to add 1 to the digit's value to give us an index from 1 to 10. When we multiply by 2, we add 11 to the digit's value to give us an index from 11 to 20. You can see the array constant with those values. Then we SUM the values for each digit, add the check digit, take it MOD 10, and if that's 0, then the check digit is valid.
You might think it would be a bit easier to just make the number 16 digits long in the TEXT, so you don't have to add the check digit separately, but here's where we run up against the 15-digit precision limit in Excel.
In the first formula, I multiplied each digit by 1 or 2, then took that result MOD 9 to get the result from table C:E. That works fine for every digit except 9, which is why I had to handle that separately.
Hope this makes some sense!