I was paying for paan at a roadside stall. The vendor held up a laminated printout — a QR code, sun-bleached, slightly crumpled at one corner. My phone scanned it in under a second. UPI confirmed. Payment done.
I stood there looking at that battered piece of paper. One corner was visibly torn. There was a grease stain across the middle. And my phone had read it perfectly.
I'd been using QR codes for years without once thinking about how they actually work. How does a grid of black and white squares encode enough information for a payment? How does the scanner know which way is up? And how — specifically — did my phone read a code with a literal hole torn out of it?
The answers are one of the better engineering stories I've come across.
🎁 Who Gave Us This Gift
QR codes were invented in 1994 by Masahiro Hara and his team at Denso Wave, a subsidiary of Toyota. The original problem had nothing to do with payments or smartphones. Toyota's factories were tracking automotive parts using barcodes, and barcodes had hit their limit — they could only hold about 20 characters and required precise alignment to scan. As manufacturing grew more complex, the bottleneck became real.
Hara's team spent two years building something better. They wanted a code that could hold hundreds of characters, scan from any angle, and work even when partially damaged. In September 1994, they landed on the design we still use today: a two-dimensional matrix of black and white squares, with three distinctive corner patterns that let any camera orient the code instantly.
They called it QR — Quick Response. The name referred to how fast it could be decoded compared to a barcode.
Here's the part that changed everything: Denso Wave held the patent but chose not to enforce it.
They made the QR code standard openly available. Anyone could use it, implement it, build on it — no licensing fees, no royalties, no permission required. In an era when technology companies were aggressively protecting intellectual property, a Toyota subsidiary quietly handed the world one of the most useful inventions of the decade.
This decision is why QR codes became universal. A proprietary QR code would have fragmented into competing standards or been squeezed out by licensing costs. The open patent meant every phone manufacturer, every app developer, every payment network could adopt it freely. Hara's team built the rocket and then gave away the launch codes.
🧩 What a QR Code Actually Contains
A QR code looks like noise but it has a very precise structure. Every element serves a specific function.
Finder patterns — the three identical square rings sitting in three corners of the code — are the first thing any scanner looks for. They are always the same size relative to the code, and always the same ratio of outer ring to inner square. No matter what angle you hold your phone at, the scanner locates these three shapes, calculates their positions, and immediately knows which way is up, what the module size is, and whether the image is skewed or warped. The fourth corner is intentionally left blank so the scanner knows which corner is missing.
Format information sits in a strip adjacent to the top-left finder. It encodes two things: the error correction level being used and which mask pattern was applied to the data. It is stored twice in different parts of the code so that even if one copy is damaged, the other can be read.
Timing patterns are alternating black-and-white strips running between the finder patterns, both horizontally and vertically. Their job is to help the scanner count modules precisely — they act as a ruler so the decoder knows exactly where one cell ends and the next begins, even on a slightly curved or distorted surface.
Data codewords fill the remaining area, encoded in one of four modes: numeric (most compact for digits), alphanumeric, binary, or Kanji.
📊 Versions, Capacity, and the Combinations
QR codes come in 40 versions. Version 1 is a 21×21 grid. Each version adds 4 modules per side, so Version 40 reaches 177×177.
| Version | Grid size | Numeric | Alphanumeric | Binary bytes |
|---|---|---|---|---|
| 1 | 21 × 21 | 41 | 25 | 17 |
| 10 | 57 × 57 | 652 | 395 | 271 |
| 40 | 177 × 177 | 7,089 | 4,296 | 2,953 |
For a Version 40 code at the lowest error correction level, a 177×177 grid contains 31,329 modules. Subtract the fixed structural elements (finders, timing, format, alignment), and roughly 18,672 modules remain as data. Each module is one bit. The total number of distinct QR codes at Version 40 is astronomically large — comfortably more combinations than atoms in the observable universe.
There's also a mask pattern: one of 8 templates XOR'd onto the data area to prevent large solid blocks of the same colour, which can confuse scanners. The encoder tries all 8 masks and picks the one that produces the most balanced distribution of light and dark modules. You see the result but never the intermediate step.
🛡️ Why a Torn, Blurry QR Code Still Works
This is the most technically remarkable part of QR codes, and it comes from an algorithm that predates them by 34 years.
In 1960, mathematicians Irving S. Reed and Gustave Solomon published a paper describing a method for detecting and correcting errors in transmitted data. The Reed-Solomon algorithm works by adding structured redundancy — extra codewords derived from the original data — in a way that lets a decoder reconstruct missing or corrupted information even when part of the message is gone.
QR codes use Reed-Solomon error correction at one of four levels:
Level L — corrects up to 7% of damaged codewords
Level M — corrects up to 15% of damaged codewords
Level Q — corrects up to 25% of damaged codewords
Level H — corrects up to 30% of damaged codewords
The trade-off: higher correction means more of the code is redundancy and less is actual data. A Level H code can have 30% of its modules physically missing, torn, or obscured and still be fully decoded — but it holds less data than a Level L code of the same size.
The reason Reed-Solomon works mathematically is that it encodes data as coefficients of a polynomial and derives check codewords by evaluating that polynomial at specific points. A decoder can reconstruct the original polynomial — and therefore the original data — even with some of its points missing, as long as the number of valid points exceeds the degree of the polynomial. Missing modules correspond to missing points. The algorithm fills them in.
The same Reed-Solomon algorithm appears in CDs, DVDs, Blu-ray discs, QR codes, NASA's deep space communications, and RAID storage systems. It's one of the most quietly deployed algorithms in existence.
That chai vendor's torn, grease-stained QR code had roughly 15% of its modules unreadable. Reed-Solomon reconstructed them from the remaining intact data, the decoder produced the original codewords, and the payment went through without the scanner ever "knowing" the code was damaged.
🇮🇳 How UPI Turned QR Codes Into Infrastructure
When India's National Payments Corporation of India (NPCI) launched UPI in 2016, they needed a mechanism that would work for a street vendor with no card terminal, no reliable internet, and a feature phone. QR codes were the answer.
The design was elegant: a merchant generates a QR code encoding their UPI ID and amount (or amount-blank for flexible payments). The customer scans it. The UPI app resolves the ID, the customer confirms, and the transfer settles — in seconds, between any two banks.
The distribution cost was essentially zero. A merchant needed a single printed QR code. No hardware, no terminal, no monthly fee. A laminated printout from a ₹10 photocopy shop was sufficient. This is what made the network reach chai stalls, auto-rickshaw drivers, and temple donation boxes in a way that card infrastructure never could.
2016 UPI launches with QR code support
2017 50 million monthly transactions
2020 2.2 billion monthly transactions
2023 10+ billion monthly transactions
2024 India accounts for ~50% of all real-time payments globally
The volumes are difficult to comprehend. India now processes more real-time digital payments than the rest of the world combined, and QR codes are the physical interface that made that possible at the bottom of the market. PhonePe, Google Pay, and Paytm all converged on the same scan-to-pay experience because the standard was open and the technology was free.
Masahiro Hara built this for Toyota's car parts. He could not have imagined that thirty years later it would be settling fruit vendor payments in Mumbai at 8am on a Tuesday.
🎯 Key Takeaways
1. QR codes were built for factories, not phones. The original problem was tracking automotive parts. The smartphone use case came two decades later.
2. The open patent made it universal. Denso Wave's decision not to enforce the patent is the single biggest reason QR codes became global infrastructure. A proprietary equivalent would never have reached this scale.
3. Reed-Solomon is why damaged codes still work. Up to 30% of a QR code can be destroyed and it remains decodable. The algorithm was published in 1960, long before QR codes existed.
4. Every element of the QR structure is deliberate. The finder squares, timing strips, mask patterns, format information — each solves a specific scanning problem. Nothing in the design is decorative.
5. UPI used QR codes as physical infrastructure. The genius of India's payment revolution was using a free, open standard that required no hardware to distribute. A printed piece of paper became a payment terminal.
✨ Final Thoughts
What I find most striking about QR codes is how much engineering is packed into something that looks like static. Three corner squares to orient a camera. Reed-Solomon polynomials to survive damage. Mask patterns to prevent the scanner from getting confused by solid blocks. Forty versions scaling from a business card to a billboard. All of it working in under a second on a phone camera, silently, billions of times a day.
And all of it free — because one engineer at a Toyota subsidiary, sitting on a patent that could have been extremely valuable, decided the world would be better served if it wasn't.
That's not a small decision. It's the kind of decision that determines whether a technology becomes infrastructure or a footnote.