If the checkout scanner malfunctions when you’re picking up a last-minute gift on your way to a birthday party, all hope is not lost—the cashier can complete the transaction by entering the number below the barcode. And while that long stream of digits might seem completely random to you, there’s a very specific system behind it.

The barcode you see on most retail products in the U.S. and Canada is known as a UPC-A, for universal product code, and the number comprises 12 digits. According to Geeky Camel, the first digit indicates which category a product falls under; the number 3, for example, denotes a health-related item, while 2 is used for certain weighed products, like meat.

The next five digits will tell you which company manufactured the product (that is, if you happen to have memorized a long list of manufacturers’ UPC identification numbers). There’s usually a space between that number and the next five-digit chunk, which corresponds to the particular product.

The final digit is what’s called a check digit, which the computer uses to verify that all the other numbers in the code have been scanned or entered correctly. The check digit is calculated from a formula that uses all the numbers listed before it. To simplify the process, let’s say you’re dealing with a three-digit number; the last digit is a check digit, and you find it by taking the difference between the first two digits. If those digits are 4 and 3, for example, your check digit is 1. If the cashier accidentally typed 421 instead of 431, the system would realize that the check digit doesn’t match the formula and would give some sort of error alert.

Of course, UPC-A barcodes aren’t the only ones in existence. As BizFluent reports, items so small that they can’t accommodate a lengthy 12-digit barcode use UPC-E barcodes, which consolidate category, manufacturer, and product information into just six digits. And EAN-13 barcodes, which are used around the world, contain the same information as UPC-A barcodes, but they also include a number that corresponds to the country where the barcode was registered. There are also different types of barcodes for books, mail, sheet music, and more.

Have you got a Big Question you'd like us to answer? If so, let us know by emailing us at bigquestions@mentalfloss.com.