The Science Behind the Scan

The Science Behind the Scan

There was a time when paying for a Rs 20 ice cream meant checking your wallet for change. A Rs 35 packet of vegetables could leave you counting coins in your palm. And if the exact amount wasn’t there, someone had to make a quick trip to a nearby shop for change.

Today, the same ice cream vendor may simply point to a small black-and-white square stuck beside the cart.

So does the neighbourhood vegetable seller

So does the chai stall, the local kirana shop and the roadside momo vendor.

From roadside ice cream carts to neighbourhood kirana shops, QR codes have made digital payments possible with just a quick scan. Photograph: (The New York Times)

You raise your phone, scan that square, enter your UPI PIN and within seconds, the money is transferred.

But what exactly happens between pointing your camera at those tiny black-and-white boxes and seeing that satisfying “Payment successful” message?

That square is more than a picture

What looks like a random collection of black and white boxes is actually a carefully structured way of storing information.

A QR code, short for Quick Response code, was invented in Japan in 1994 by engineer Masahiro Hara, originally to track car parts in factories. Unlike a traditional barcode, which stores information along a single horizontal line, a QR code stores information across a two-dimensional grid.

Those familiar black-and-white squares are carefully structured data grids, designed to store information that a phone can read in seconds. Photograph: (QR tiger)

Those little black and white squares are called modules. Depending on how much information is being stored, QR codes can have different versions, ranging from 21 × 21 modules to 177 × 177. More information generally means more modules.

For a UPI payment, the encoded information can include the merchant’s UPI ID or virtual payment address, merchant name, transaction reference and, depending on the QR type, the amount to be paid.

So the QR code is not a picture of the shopkeeper or their bank account. It is a compact, machine-readable package of payment instructions.

First, your phone has to find the code

Ever noticed the three large squares sitting in the corners of a QR code?

They are called finder patterns.

Think of them as signposts telling your phone’s camera: “This is the QR code. Start reading here.”

Their distinctive black-and-white pattern allows the camera to identify the code quickly and determine its orientation, even when you scan it from an angle. 

The three distinctive squares at the corners are finder patterns, helping a phone’s camera locate and orient the QR code before decoding it. Photograph: (QR Tiger)

The phone can then correct the perspective and work out the grid of modules it needs to read. QR codes are designed to be readable from different angles because of these position-detection patterns.

There is also a small blank area around the QR code called the quiet zone. It helps the scanner distinguish the code from the surrounding poster, sticker or shop counter.

Your camera is really decoding data

Once the camera identifies the grid, it isn’t simply “seeing” black and white.

The QR-reading software converts the pattern of modules into digital data — essentially a sequence of encoded bits and bytes. The QR format also contains information that tells the decoder how the data has been structured.

In a UPI QR, that decoded information can point the payment app towards a particular payee. Your UPI app reads those parameters and translates them into something useful on screen: who you are paying, and sometimes how much.

This is why scanning a QR can instantly open a payment screen with the merchant’s details already filled in.

Static or dynamic? There is a difference

That familiar QR code permanently stuck to a small shop counter is often a static QR. The merchant’s payment details remain embedded in the code, while you enter the amount yourself.

A dynamic QR, on the other hand, can carry transaction-specific information. For example, the amount and transaction reference can be generated for a particular purchase. NPCI’s specifications distinguish between these QR types and define parameters such as payee address, transaction reference and amount.

The three distinctive squares at the corners are finder patterns, helping a phone’s camera locate and orient the QR code before decoding it. Photograph: (LinkedIn/ @Chandra Sekhar)

That is why you may see a QR appear on a restaurant billing screen or a digital checkout page with the exact amount already waiting for you.

Why does a damaged QR code still work?

This is where the mathematics gets particularly clever.

A QR code doesn’t just store the information you need. It also contains additional data that acts like a mathematical backup.

This is called error correction.

QR codes use Reed-Solomon error correction, which adds extra information to the original data. If some of the modules become unreadable because of dirt, scratches or damage, the decoder can use that additional information to reconstruct the missing data. There are four error-correction levels, with higher levels offering greater recovery at the cost of making the code larger.

That is why a QR code pasted on a shop counter can look like it has survived years of dust, rain and fingerprints — and still accept your Rs 50 payment.

From a scan to a bank transfer

Now comes the part where the QR code hands over the job to UPI.

Once your app has decoded the payment information, it displays the recipient and amount. You check the details and authorise the transaction using your UPI PIN.

The QR code itself does not transfer or store your money. It essentially provides the information needed to initiate the payment.

Thanks to Reed-Solomon error correction, QR codes can often remain readable even when parts of the pattern are scratched, dirty or damaged. Photograph: (All Blogs)

UPI then handles the actual ttransaction between the participating banks and payment-service providers. Your bank account is debited and the recipient’s account is credited, while the payment app shows you the result.

So, in simple terms: the QR code tells the app where and how to pay; UPI moves the money.

A tiny square doing a very big job

The next time you scan a QR code at a roadside stall, look at it for a second.

Those seemingly random black-and-white boxes combine data encoding, image recognition, geometry and error-correcting mathematics, all inside a tiny square.

And somewhere between the vendor saying “UPI kar do” and your phone chiming with “Payment successful”, a tiny square has done a remarkable amount of work – identifying a pattern, decoding data, verifying payment details and connecting you to the digital payments network.

All that science, packed into a few centimetres of black-and-white squares, works quietly in the background and is over in just a few seconds.

Sources:

‘How does a UPI QR code work? It hides extraordinary mathematics in plain sight’ Radifaf Kabir, for India Today, Published on 18 May 2026.

‘What is UPI QR code and How it Works’ by Easebuzz

Leave a Reply

Your email address will not be published. Required fields are marked *