You have probably scanned one this week. A small square of black and white specks on a café table, a boarding pass, a parking meter, a poster on a train. You point your phone at it, it buzzes, and a menu or a payment page opens.

That square was not designed for phones, or for cafés. It was designed in Japan in 1994 to keep track of car parts on a factory floor. So why did a car-parts factory need a new kind of code, and how did something built for one factory end up in billions of pockets?

A barcode is enough for a can of soup

Start with the code you already know: the barcode, the row of black stripes on almost everything in a supermarket. When the cashier scans it, the beep carries one short number. The store’s computer looks that number up and finds the name and price. For a can of soup, that is all anyone needs.

A box of parts in a car factory asks a lot more of its label. What is inside, how many, who made it, when, and which line it is going to. And in Japan, that list was getting longer. Factories had moved toward building many different models in smaller batches, so the number of parts, and the information about each one, kept growing.

A barcode holds only about 20 characters. So the labels multiplied. At Denso, a parts maker in the Toyota group, a worker scanning a single delivery might have to read ten or so barcodes, one after another.

Denso was no stranger to barcodes. It already used them on the cards that travel with parts in Toyota’s way of making cars, telling each step what to send next. The barcode had done the job for years. It had simply run out of room.

Workers wanted a code that held more and could be read in one go. Denso’s development team took the problem on, with an engineer named Masahiro Hara leading a team of just two.

A square that tells you where it is

The first idea came, Hara has said, from the board game Go, which he played on his lunch breaks. Go is played by placing black and white stones on a grid of lines, so the board fills up with a pattern of black and white that runs both across and down. That was the hint. A barcode only stores information in one direction, from left to right. A grid of black and white squares, like the stones on the board, stores it in two directions at once, so it can hold far more.

It did. A QR code can carry up to 7,089 digits, roughly 200 times what a barcode holds. It can also store the characters used to write Japanese, which mattered in a Japanese factory.

The harder part was speed. A scanner looking at a crowded label has to find the code before it can read it. Hara’s answer is the thing everyone recognises a QR code by: the three big squares in its corners. Each is a solid black square, wrapped in a thin white ring, wrapped in a thin black ring. Draw a line through the middle and you cross thin black, thin white, a black band three times as wide, thin white, thin black: a ratio of 1:1:3:1:1. The line can run across, down or at a slant; the rhythm stays the same.

The team chose that rhythm after going through a vast amount of printed material, looking for the pattern that turned up in them least often. So when a scanner sees it, it can be fairly sure it has found a code, and with three corners it knows which way up the code is. That is why you can hold your phone at any angle.

All of this made the code quick to find and quick to read. Denso said its code read more than ten times faster than other two-dimensional codes of the time, and named it for that: QR, for Quick Response.

Factories are also dirty. Labels get oily, scuffed and torn. So the code repeats part of its information in a way that lets the scanner rebuild what is missing. At the strongest setting, a QR code can still be read with about 30 percent of it damaged. The whole project took about a year and a half.

Why it left the factory

A good code for car parts does not by itself end up on a café table. Two things carried it out.

The first was a decision about the patent. Denso filed for a patent in 1994 and kept it. But for the standard QR code, the company promised not to enforce it: anyone could make and read QR codes without paying. Its stated reason was simple: it wanted as many people as possible to use them. Years later, Denso’s chairman looked back on it as a choice made by leaders who were aiming high. Because no one had to pay, the code could become a public standard. It was made an industry standard in 1997, a Japanese national standard in 1999 and an international one in 2000.

The second was the phone camera. In 2002, the ability to read QR codes was built into a mobile phone in Japan, and a code could now be read by anyone with a phone in their pocket, not just by a scanner in a factory. When smartphones with cameras spread everywhere, the code was already free and ready. By 2014, it was so widely used that the development team won the Popular Prize, chosen by public vote, at the European Inventor Award.

Then came the pandemic, and for many people scanning became a daily habit. Restaurants that no longer wanted to hand out shared menus put a code on each table instead. In Japan, some went a step further and let customers order and pay through the code too.

Back to your phone

So why a car-parts factory? Because that was where a label had to say far too much for a barcode, and had to be read in a hurry, from any angle, covered in grease. The factory’s problem shaped the code. And it reached your phone because the company that made it let everyone use it for free.

Next time you scan a menu, look at the three squares in the corners. They are there so a scanner on a busy factory line could find the code at a glance, and their black-and-white rhythm was picked because it was the pattern the team found least often in print.