Barcodes for Developers: What the Stripes Actually Encode
Every barcode you've ever seen is just a number rendered as a pattern of lines. That's it. There's no image recognition, no machine learning, no computer vision involved in reading a standard barco...

Source: DEV Community
Every barcode you've ever seen is just a number rendered as a pattern of lines. That's it. There's no image recognition, no machine learning, no computer vision involved in reading a standard barcode. A scanner shines a light, measures the reflections, decodes the widths of the bars and gaps into digits, and looks up those digits in a database. The intelligence is in the database, not the barcode. But the encoding schemes are more interesting than most developers realize. Here's what's actually happening inside those stripes. UPC and EAN: the ones on products The barcode on a can of soda is almost certainly UPC-A (12 digits, used in North America) or EAN-13 (13 digits, used everywhere else). UPC-A is actually a subset of EAN-13 with a leading zero. An EAN-13 barcode like 5901234123457 encodes: First 3 digits: country/region prefix (590 = Poland) Next 4-5 digits: manufacturer code Next 4-5 digits: product code Last digit: check digit The check digit is a weighted sum of the other 12 dig