How Do QR Codes Work?

Key Takeaways QR codes are an evolution of barcodes, holding more data & originating in Japanese auto-manufacturing. QR codes use more advanced technology than traditional barcodes, read by machine vision … Read more

Taylor Bell

Taylor Bell

Published on Apr 26, 2024

How Do QR Codes Work?

Key Takeaways

  • QR codes are an evolution of barcodes, holding more data & originating in Japanese auto-manufacturing.
  • QR codes use more advanced technology than traditional barcodes, read by machine vision algorithms.
  • QR codes can store various data beyond URLs, evolving for different applications with smartphone improvements.

QR codes have succeeded. They’re in use for everything from cinema tickets to underground raves. If you need to share a link, download an app, or even validate someone’s health status, you can use a QR code. But how does this technology work… and would you be surprised to learn it’s been around since the 90’s? We’ll examine how exactly QR codes work, why they’ve improved so much on modern devices, and how these funny little squares came to be a staple of our everyday life.

QR codes are just fancy barcodes

They have roots in Japanese auto-manufacturing

QR codes are, fundamentally, an evolution of barcodes. One dimensional barcodes store a volume of data by arranging a series of lines at varying distances, which can be read by light and interpreted as data. I’m sure you have seen common barcodes everywhere, but there are a significant number of alternative and competing standards. You’ll probably recognize some of the slight differences between them, varying in size, details of the standard, and how many lines there are. One-dimensional barcodes don’t store much data, so they typically just represent a number, which is often the product code of the item they’re attached to.

The gallery above contains some other barcode standards, in order: UPC, Code128, PDF417, an Aztec Code, and a data matrix.

“” data-modal-id=”single-image-modal” data-modal-container-id=”single-image-modal-container” data-img-caption=””””>

QR code for Copilot on Windows 11 lock screen

Related

Microsoft puts a hold on spamming Windows 11 lock screen with Copilot QR codes

Microsoft’s latest controversial promotional strategy involved inserting QR codes for Copilot on the Windows 11 lock screen.

A 2D barcode is what it sounds like – a 1D barcode with a second dimension added. Instead of encoding data in a single row of lines, they encode data in two dimensions. This massively increases the number of bits of data that can be stored. If a 1D barcode can store n-bits, a 2D barcode can store n^2. QR codes are nothing more than a specific type of 2D barcode, with some additional features.

The first QR codes were designed for production line usage

QR codes were originally invented for the automotive industry in Japan, as production lines became increasingly automated. QR codes allowed more data to be stored than a normal barcode, as well as more error checking. They were utilized to label parts as they moved through the production line.

QR codes are normally scanned differently

While QR codes have their roots in barcodes, they aren’t normally scanned in the same way. While a barcode scanner relies on an optical beam of light scanning each bar individually, QR codes normally use much faster and more sophisticated machine vision technology. It is possible to scan QR codes in the same way as barcodes, but uncommon now, as machine vision technology has improved significantly.

Squares in squares, in squares?

Image showing the structure of QR codes.

Source: Wikimedia Commons

In making the move from a 1D to 2D barcode, we need some extra features. The most obvious of these is the large orientation squares on each QR code, known as position detection patterns. These squares are used by software to initially locate the QR code. Less noticeable is a smaller square in the corner not featuring a large square, which is used to ensure the orientation of the QR code is correct, and is known as the alignment pattern.

There are also some alternating lines between each of the position detection patterns, which are known as timing patternsas well a standard-enforced area of white space (known as the quiet zone) around the edges of the QR code, which helps identification (although many QR codes skip this).

The combination of these position detection and alignment patterns makes the QR code quickly and easily located by machine vision algorithms.

Format and version bits

Once the QR code has been located and oriented, the version information of the QR code can be read. This information is stored in specified squares in a designated location, and denotes the size of the QR code we’re looking at.

Having identified the version and size of the QR code, and oriented it correctly, the market format for the QR code can be read. There are two unique copies of this, and it contains information on the error correction level and the mask pattern bits. The error correction level is one of four values represented by two bits on the QR code (i.e. two individual tiny squares), encoding one of low, medium, quartile, or high values, which allow 7%, 15%, 25%, or 30% respectively of the total QR code that could be destroyed and the data could still be recovered.

QR codes use an error correction algorithm called Reed-Solomon. We won’t go into how this works (lest this article becomes a CS lecture), but it’s highly effective and used in everything from DVDs to RAID6. Reed-Solomon allows either partial reconstruction or just detection of errors, depending on how much of the data is damaged.

Once all this information has been identified, we can begin reading the data bits.

Reading QR codes

Decoding QR codes by hand is hard, but not impossible

Diagram showing how QR codes are read.

Source: Wikimedia Commons

The data area of the QR code is read from the bottom right-hand corner, with the QR code oriented with the alignment pattern in the bottom right. The size of the data area varies, with some encoding several thousand characters. Starting from the bottom corner, the QR code reads individual squares (or pixels) in blocks of 8. What each pattern corresponds to depends on the encoding setting of the QR code, but they commonly represent ASCII (i.e. alphanumeric) characters. The length of the code and encoding mode normally come first, followed by the data block, followed again by data used for error checking.

The QR code is read in a snaking pattern from the bottom right to the top left, one block of 8 pixels at a time. This data is extracted, ordered, and then decoded to retrieve the original string.

QR codes often contain URLs

URL redirection can be used to open an app with a QR codeAn image of a app with a QR code on it.

By far the most common use of QR codes is to store URLs. These URLs can be handled by your device in a variety of ways, everything from opening a webpage in a browser to starting an email. URLs can be used for URL redirection, a technique where a webpage is interpreted by your device as opening an app, which then passes metadata to the app. This is likely what you’ve used if you have scanned a QR code which has opened on a website before opening up an app with some metadata or context.

But not always…

There are plenty of uses for QR codes beyond URLs. Most smartphones can open a link in a URL using their default camera app, but other apps with access to the camera can use QR codes for all sorts of other purposes. This might be everything from geocaching to spawning 3D augmented reality monsters. The speed and usability of QR codes for alternative applications has improved alongside smartphone cameras and general processing power.

Your device decides how to interpret the data

The best way to understand QR codes is to keep them simple. A QR code is just a message. It represents a string of characters of some length between very short to 4000+ characters. Decoding the QR code has no effect in itself – what happens next is decided by the app or the user decoding it. Different apps can use QR codes for a variety of purposes. Tickets often contain a UUID (Universally Unique Identifier) which represents your ticket, and many health systems or COVID vaccination passes use similar systems. The standard of the QR code itself doesn’t change, just its application and interpretation.

Graphic QR codes

Ever wonder how some people get Logos on their QR codes?A QR code with a Scan Me logo in the middle.

One oddity of QR codes you might have seen is codes which feature a logo, text, or image in the middle. How do these work?

Leaving an image in the middle of a QR code is not actually supported by the standard for QR codes – instead it’s relying on error checking. The image occupies the location where data should be, effectively damaging the QR code. These images typically have a high error correction setting, and rely on the image interpreter decoding the value from error correction bits, rather than from the area data is supposed to be stored in.

While more aesthetically pleasing (and good for branding), this does leave these QR codes more vulnerable to damage, reducing the area of the QR code that can possibly become damaged before the code becomes unreadable.

QR codes are here to stay

One thing about QR codes is clear: they’re here to stay. Many prophesied the death of QR codes in favor of flashier technologies like NFC. But QR codes can be projected pretty much everywhere, onto buildings or any type of display area, allowing hundreds or thousands of people to scan them at once. This mass-market appeal and almost universal adoption by smartphone providers has turned QR codes into a wildly powerful technology, and one that’s certainly here to stay.

Partager cet article

Inscrivez-vous à notre newsletter