how the luhn algorithm works
the luhn formula algorithm was developed by a german computer scientist named hans peter luhn in 1954 while working as a researcher at ibm 1 the exact workings of the algorithm are based on modular arithmetic a mathematical technique developed by carl friedrich gauss in the early 19th century although its detailed workings are rather complex it is best known for allowing computers to quickly assess whether the credit card numbers provided by customers are accurate 2the way it does so is by applying a series of computations to the credit card number given adding up the results of those computations and checking whether the resulting number matches the expected result if it does then the credit number is deemed valid if not the algorithm will reject the credit card number indicating that the user made an error when inputting the number from a customer s perspective we use the luhn algorithm all the time without even realizing it when placing orders online or using a merchant s point of sale pos terminal computer systems are able to quickly tell when we have made a mistake inputting our information this is because the luhn algorithm has been incorporated into those systems programming without it we would need to wait until the entire purchase order is submitted before realizing whether the transaction was approved the luhn algorithm in other words helps us quickly identify user errors and thereby speed up the pace of transactions real world example of the luhn algorithmone of the central concepts within the luhn algorithm is the use of so called check digits these digits consist of numbers that are inserted into the broader number sequence in order to help verify or check whether the whole number is authentic for credit cards the check digit consists of a single digit printed at the end of the credit card number rather than being specifically chosen by the credit card company the check digit is instead automatically determined by the luhn algorithm based on the preceding numbers in the sequence when users enter their credit card numbers to complete transactions the payment processing software can use the luhn algorithm to detect whether the specified number is accurate based in part on its check digit today the luhn algorithm is integrated into popular programming languages and code libraries making it relatively easy to include luhn based identification number verification in new software applications 