How does a UPI QR code work? It hides extraordinary mathematics in plain sight

Every UPI payment you make by scanning a QR code triggers a cascade of sophisticated mathematics in under a second. Here is the science of why that crumpled, faded square on a shop counter still processes your payment perfectly every single time.

Advertisement
Every UPI payment you make by scanning a QR code triggers a cascade of brilliant mathematics in under a second. (Photo: Radifah Kabir/India Today)
Every UPI payment you make by scanning a QR code triggers a cascade of brilliant mathematics in under a second. (Photo: Radifah Kabir/India Today)

Somewhere in India right now, a transaction is happening. At a sweet shop in Chandni Chowk. At a medicine counter in Imphal. At a roadside stall where a vendor has never owned a cheque book in his life.

A phone goes up. A square is scanned. Money moves.

The square is the size of a postage stamp. It has no battery, no signal, no moving parts. It is ink on paper. It has been rained on, sun-bleached, written on, and half-peeled off walls across the length and breadth of this country.

advertisement

And yet it works. Every single time.

In 2016, when UPI launched in India, this square was an experiment. Today, India processes over 18 billion UPI transactions every month, more than any other country on Earth.

The black and white square powering India's UPI revolution is built on some of the most sophisticated mathematics ever conceived by human beings. (Photo: Radifah Kabir/India Today)
The black and white square powering India's UPI revolution is built on some of the most sophisticated mathematics ever conceived by human beings. (Photo: Radifah Kabir/India Today)

Every one of them passes through a pattern of black and white that most people have never once thought about.

They should. Because inside that square is some of the most extraordinary mathematics ever put to practical use. The same mathematics that Nasa uses to receive signals from Voyager, a spacecraft now 24 billion kilometres from Earth.

This series from India Today Science explores the why and how behind everyday phenomena we notice, wonder, but often overlook. Each edition breaks down the science behind familiar experiences in simple terms.

Today, we look at the extraordinary intelligence and mathematics hiding inside the QR code that powers every UPI payment you make.

THE GO BOARD THAT STARTED IT ALL

The Quick Response code, or QR code, was invented in 1994 by Masahiro Hara, an engineer at Denso Wave, a subsidiary of Toyota.

The problem he was trying to solve was unglamorous. Car parts moving through a factory were being tracked with standard barcodes.

A barcode is the familiar pattern of thin and thick vertical black lines printed on almost every grocery packet and medicine box. A laser scans horizontally across those lines, from left to right, measuring how wide each black line and white gap is.

Those varying widths translate into a string of numbers. Because the laser only ever moves in one direction, a barcode can only store as much information as a single horizontal sweep can capture.

A QR code holds up to 7,089 numeric characters, compared to the 20 a standard barcode can store, all packed into a square the size of a postage stamp. (Photo: Radifah Kabir/India Today)
A QR code holds up to 7,089 numeric characters, compared to the 20 a standard barcode can store, all packed into a square the size of a postage stamp. (Photo: Getty)

Think of it like reading a single line of text. You can only fit so many words on one line. A QR code, by contrast, is like a whole page. Information runs both across and down, which is why it holds so much more.

A barcode holds roughly 20 characters, which means 20 individual letters, digits, or symbols. It fails if tilted. It gives up entirely if smudged. Hara needed something faster, denser, and tougher, something that could one day power millions of UPI payments without breaking a sweat.

The answer came to him while watching a colleague play Go, the ancient Japanese board game played on a grid of black and white stones. The grid, Hara realised, could carry information in two directions simultaneously, horizontally and vertically, instead of just one.

According to Denso Wave, the resulting QR code could hold up to 7,089 numeric characters, which are simply digits like 0 to 9, or up to 4,296 alphanumeric characters, which means a mix of letters, numbers, and symbols like the ones in a UPI payment address or a web link.

Every UPI payment begins with a scan and ends with a mathematical miracle completed in under a second. (Photo: Getty)
Every UPI payment begins with a scan and ends with a mathematical miracle completed in under a second. (Photo: Getty)

advertisement

A standard barcode holds roughly 20 characters, enough for a simple product code. A QR code holds enough for an entire paragraph.

Denso Wave made the patent freely available to the world. That single decision turned a factory tool into a global standard, and eventually into the backbone of India's UPI payment system.

Quick Response is a name Hara chose to reflect the code's ability to be decoded at high speed. It was not marketing. It was a promise the code has kept every single time.

WHY YOUR PHONE LOCKS ON IN MILLISECONDS

Every time you open your UPI app and point your phone at a QR code, your phone's camera does something remarkable in a fraction of a second.

Look at any QR code carefully. In three of its corners sits a bold square within a square, unmistakable against everything around it.

advertisement

These are called finder patterns. Think of them as the QR code's address markers, fixed landmarks that tell your phone's camera exactly where the code begins, how big it is, and which way it is facing, even if you are holding your phone at an angle.

The scanner identifies each finder pattern using a specific mathematical ratio embedded in its design.

The same error correction mathematics that keeps Voyager spacecraft data intact across 24 billion kilometres also ensures your UPI payment goes through on a faded, crumpled QR code. (Photo: Radifah Kabir/India Today)
The same error correction mathematics that keeps Voyager spacecraft data intact across 24 billion kilometres also ensures your UPI payment goes through on a faded, crumpled QR code. (Photo: Radifah Kabir/India Today)

Each finder pattern is made up of tiny squares called modules, which are simply the individual black or white dots that together form the entire QR code, the way individual tiles form a mosaic.

The sequence of dark, light, and dark modules within each finder pattern always follows a fixed proportion of 1:1:3:1:1.

In simple terms, this means the pattern is always one dark square, one light square, three dark squares, one light square, and one dark square, in that exact order.

advertisement

This specific arrangement is so uncommon in everyday images and backgrounds that the scanner can pick it out almost instantly, from any angle, at any distance, in almost any lighting.

Reed-Solomon error correction, developed in 1960, allows a QR code to recover up to 30 per cent of its data even when that portion is completely destroyed. (Photo: Getty)
Reed-Solomon error correction, developed in 1960, allows a QR code to recover up to 30 per cent of its data even when that portion is completely destroyed. (Photo: Getty)

Once it finds all three corners, it corrects for any tilt or distortion using a process called inverse perspective transformation.

In everyday language, this means the phone takes the skewed, angled image its camera has captured and digitally presses it flat, the way you might smooth out a crumpled piece of paper before reading what is written on it.

Only after that correction does the actual reading begin, and your UPI payment moves forward.

WHY A DAMAGED QR CODE STILL READS PERFECTLY

You have probably noticed that even a scratched, faded, or partially covered QR code still processes your UPI payment without any problem. This is not luck. It is mathematics.

Every QR code carries significantly more information than the message it contains.

Embedded within the pattern are extra mathematical values called error correction codewords.

Think of these as a backup copy of the data, stored inside the code itself, that allows the scanner to rebuild missing pieces even when part of the code has been damaged.

The three bold corner squares in every QR code, known as finder patterns, follow a mathematical ratio so specific it almost never appears by accident in any natural image. (Photo: Radifah Kabir/India Today)
The three bold corner squares in every QR code, known as finder patterns, follow a mathematical ratio so specific it almost never appears by accident in any natural image. (Photo: Radifah Kabir/India Today)

These codewords are produced by an algorithm called Reed-Solomon error correction, developed in 1960 by mathematicians Irving Reed and Gustave Solomon at MIT Lincoln Laboratory, one of the world's leading scientific research centres.

An algorithm is simply a set of step-by-step instructions that a computer follows to solve a problem, much like a recipe tells a cook exactly what to do and in what order.

Reed-Solomon works on a beautifully simple idea. Every number in the original data is called a coefficient, which is simply a number that plays a fixed role in a mathematical expression, the way a specific ingredient plays a fixed role in a recipe.

Reed-Solomon takes all those numbers and uses them to build a smooth mathematical curve, called a polynomial, on a graph. It then calculates several extra points that lie along that same curve and stores them inside the QR code alongside the original data.

A QR code is not a picture. It is a mathematical object, encoding data in two directions simultaneously, horizontally and vertically, across a grid of precisely arranged black and white squares. (Photo: Getty)
A QR code is not a picture. It is a mathematical object, encoding data in two directions simultaneously, horizontally and vertically, across a grid of precisely arranged black and white squares. (Photo: Getty)

If part of the code is later scratched, torn, or obscured, the scanner uses those extra stored points to reconstruct the full curve and recover the missing data, the same way a detective can piece together what happened from the clues that remain. Your UPI payment goes through regardless.

This is the same error correction system used by Voyager spacecraft to send data back from the edge of the solar system, where signals are so faint that large chunks of information arrive corrupted.

The same system that lets a scratched CD play without skipping a beat. It is also what allows a brand logo printed over the centre of a QR code to cause no scanning failure. The logo has destroyed part of the data. Mathematics has already accounted for it.

QR codes offer four levels of this protection. Level L recovers up to seven per cent of lost data. Level M handles 15 per cent. Level Q handles 25 per cent. Level H, the highest, recovers up to 30 per cent of the code even if that entire portion is completely unreadable.

WHY THE QR CODE NEVER LETS YOUR UPI PAYMENT FAIL

There is one final layer of engineering that makes every UPI scan reliable, and most people never know it exists.

Think about what happens when you try to read text printed in black ink on black paper. Your eyes cannot make out anything because there is no difference between the letters and the background.

A camera scanning a QR code faces exactly the same problem.

When data is converted into a QR code, it sometimes accidentally creates large patches of all black or all white squares.

The idea for the QR code came to its inventor, Masahiro Hara, while watching a colleague play the ancient board game Go on a grid of black and white stones. (Photo: Getty)
The idea for the QR code came to its inventor, Masahiro Hara, while watching a colleague play the ancient board game Go on a grid of black and white stones. (Photo: Getty)

A camera looking at those patches cannot tell where one square ends and the next begins. It loses track completely. Your UPI payment fails before it even begins.

To stop this from happening, every QR code goes through one final step before it is printed or displayed. This step is called masking.

Masking is simpler than it sounds. The QR code system takes the finished code and runs it through eight different mathematical patterns, one at a time.

Each pattern flips certain black squares to white and certain white squares to black in a different way.

After testing all eight, the system picks whichever pattern produces the most evenly spread mix of black and white across the entire code. The result is a code with enough contrast for any camera, in any lighting, to read cleanly every single time.

India processes over 18 billion UPI transactions every month, all of them moving through a square of ink on paper that contains some of the most elegant applied mathematics in existence. (Photo: Radifah Kabir/India Today)
India processes over 18 billion UPI transactions every month, all of them moving through a square of ink on paper that contains some of the most elegant applied mathematics in existence. (Photo: Radifah Kabir/India Today)

The specific pattern chosen is quietly recorded inside the code itself, next to the finder patterns, so that when the scanner reads the code, it knows exactly how to undo the masking and recover the original data underneath.

India processes over 18 billion UPI transactions every month. Every single one that begins with a phone pointed at a QR code passes through this entire sequence in under a second.

The square on that shop counter is still there, a little more faded now, the laminate peeling at one corner.

The UPI payments still go through. The mathematics inside has not changed. It was always this precise. This patient and extraordinary.

This is the beauty of mathematics.

#TheDailyWhy

- Ends
Published By:
Radifah Kabir
Published On:
May 18, 2026 08:00 IST