Barcodes and QR Codes: The Math That Scans
The beep is arithmetic talking.
By Daon Opus · Updated November 16, 2026
The self-checkout rejected my daughter's apple and she blamed the apple. Three beeps, three red lights, one fruit held at allegedly wrong angles while the scanner insisted the sticker was lying. Three red lights, zero ambiguity, one embarrassed apple. We typed the four-digit code by hand, the machine accepted it instantly, and she announced that barcodes were stupid. They are the opposite: the sticker had a scuffed stripe, the scanner caught the damage instead of inventing a price, and the refusal was the math working. A wrong price scans silently; a damaged code argues out loud. Silence would have been theft; noise was the receipt.
Barcodes turn numbers into patterns of light and dark that lasers read; QR codes do the same in two dimensions, with backup math woven in, insurance against the real world of smudges and tears (Wikipedia, QR code). Five sections below decode the decoders: the stripes that check themselves, the three squares that orient, the backup that forgives damage, the bites to watch for, and the weekly habit that turns shopping into reading practice.
Stripes that count themselves
A UPC barcode is twelve digits wearing a striped costume: the bars encode the digits, and the last digit checks all the others. Add the odd-position digits, triple them, add the even-position digits, and the total must land on a multiple of ten, the turnstile every price must pass; the final digit exists solely to make that happen. Cashiers never do this arithmetic, but every beep certifies it passed. Millions of silent audits per hour, all performed by light. The check digit is a bouncer who knows the guest list by heart. No ID, no entry, no exceptions even for fruit.
Our binary guide reads the world as on-and-off, which is exactly what a laser sees: dark bars absorb, light gaps reflect, on and off all the way down. A zebra crossing for photons, read at speed. The boundary is clean: binary counts in on-off, barcodes ship decimal digits through on-off stripes. Counting versus carrying, same physics, different cargo. The laser cannot tell which errand it runs.
Our modular arithmetic guide runs the clock math behind the check: multiples of ten, remainders, wrap-around. The same clock face that tells time tells truth. The barcode's self-test is remainders doing retail security, catching single-digit errors and most swaps before money moves. My daughter's apple failed the test honestly, which beats passing it dishonestly at every price point. An honest failure costs a re-scan; a dishonest pass costs a stranger money.
| Code | Holds | Survives |
|---|---|---|
| UPC barcode | 12 digits | Clean print only |
| QR code | Up to 7,089 digits | Up to 30% damage |
Three squares that orient
Every QR code wears three big squares in its corners, finder patterns that tell the camera which way is up. The ratio of their bands, one-one-three-one-one, was chosen because it almost never occurs in ordinary printing, a signal designed to be unmistakable. In 1994 Denso Wave's Masahiro Hara picked it after studying Go boards for inspiration: black and white stones had already solved the problem of reading a grid at a glance. Ancient game, modern checkout, same eyes. Hara studied stones; the stones had done the research centuries early.
Orientation solved, the rest is placement: data modules fill the grid in a zigzag from the corner, timing patterns regulate the rows like lane markings, and format information announces the error-correction level like a luggage tag. A phone held upside down reads the same code because the three squares vote on rotation first. Democracy of corners, with a unanimous result every single time. Design the landmarks well and the map reads itself from any angle, which is why no one teaches children how to hold the phone. Good signage eliminates entire curricula. The squares teach the phone instead. Nobody graduated from holding-phone school, yet everyone passes.
Capacity scales with version: forty sizes from 21-by-21 to 177-by-177 modules, holding up to 7,089 digits or about four thousand letters at the lightest protection. Bigger grid, bigger appetite, same three corner squares. Menus, tickets, Wi-Fi passwords, vaccine certificates, all ride the same grid. The pandemic turned restaurant tables into QR galleries, which means a car-parts label from 1994 now orders dinner. Factories invent; emergencies distribute. Inventions outgrow their inventors as a rule, not an exception. Car parts begat menus the way mainframes begat phones.
The backup that forgives damage
Tear a QR code and it often still scans, because Reed-Solomon error correction packs mathematical backup bytes alongside the message. Four levels trade capacity for toughness: low survives about seven percent damage, medium fifteen, quartile twenty-five, high thirty. Choose the level by counting the hazards between printer and scanner. A logo stamped in the middle counts as deliberate damage, and high-level codes absorb it while still decoding. The apple's barcode had no such backup, which is exactly why it argued instead of guessing. Guessing is for quizzes; checkout demands certainty.
Interleaving spreads the backup across the grid so one scratch cannot kill one block: neighboring squares belong to different code groups, and localized damage becomes a small wound in many groups rather than a fatal one in a single group. It is the same wisdom as not storing all eggs in one basket, expressed in finite-field arithmetic. Engineers who pack suitcases and engineers who pack bytes share one philosophy. Spread the risk, survive the trip.
Our codes and ciphers guide hides messages so enemies cannot read them. The boundary runs the other way here: barcodes publish messages so machines cannot misread them. Secrecy versus scannability, same alphabet of tricks, opposite loyalties. One math family, two professions that would barely recognize each other at dinner. Same mathematics, opposite table manners.
When the code bites back
Any sticker can lie. Scammers paste their own QR codes over parking meters and restaurant tables, and the phone obeys the top sticker without asking questions, a practice researchers call attagging. The code still scans perfectly; it just points somewhere criminal. Error correction guarantees the message survives, never that the message is honest. Reading reliably and reading safely are different subjects sharing one camera. The lens is innocent; the sticker may not be.
Phishing by QR surged because email filters read text, not pictures: malicious codes in phishing mail rose from eight million in January 2026 to nineteen million that March. The defense is one habit deep: preview the URL before opening, and type payment addresses by hand instead of scanning them off equipment. Scanners are trusting by design, which is why the skepticism has to live in the human. Machines verify the math; only people verify the motive.
The one habit: Sunday scan
Every Sunday, pick three codes in the house and read them like documents: a barcode's country prefix from an online lookup, a QR code's version guessed from its size, one damaged label tested for how much abuse still scans. My daughter's notebook holds a rogues' gallery of scuffed stickers now, each with a verdict, scans or argues. The argues pile grows faster than the scans pile, which says the habit works. Fifty-two Sundays a year is fifty-two reminders that the beep is a certificate, not a noise: something counted, something checked, something passed. Three verbs per beep, and the store runs on all three.
Decode one code in the house this week. Our free math apps drill the remainders these checks run on, and Math Q&A is where to bring a beep that won't behave.