How it works

How QR codes work, and how to scan them safely

A QR code stores data in a grid of black and white squares that a camera can read from any angle. Learn how they are built, why they survive damage and how to stay safe.

Plugpixels Editorial TeamTechnology 6 min read
A café table seen from above with a menu stand, a coffee cup and a hand holding a phone up to scan a printed card

QR codes work by storing data as a grid of small black and white squares that a camera can read quickly from almost any angle. Your phone finds three large corner squares, works out the grid, and turns the pattern into text, usually a web address. Built-in error correction means a scratched or partly covered code often still scans.

This explainer covers how a QR code is structured, how your camera reads it, why damaged codes still work, what static and dynamic codes are, and how to avoid the scams that use them.

What is a QR code?

QR stands for Quick Response. The format was invented in Japan in the 1990s to track car parts in factories, where workers needed something faster to read than a traditional barcode. It is now an open international standard, free to use, which is why it appears on menus, tickets, posters, packaging and payment terminals.

A normal barcode stores data in one direction, as the widths of vertical lines. A QR code is two-dimensional: it stores data both across and down, so it can hold far more in a small space. A typical code holds a web address of a few dozen characters, but the largest versions can hold a few thousand characters of text.

What are the parts of a QR code?

Every square in a QR code is called a module, and each one is a bit: dark for one value, light for the other. Some modules are fixed patterns that help the reader find and orient the grid, and the rest carry data and error correction.

Codes come in sizes called versions, from a small 21 by 21 grid up to much larger grids. Bigger versions hold more data but need a sharper image to read.

  • Finder patterns: the three big squares in three corners, which tell the scanner where the code is and which way up it is.
  • Alignment pattern: a smaller square near the fourth corner on larger codes, which helps correct for a tilted or curved surface.
  • Timing patterns: alternating lines between the finder squares that show the size of each module.
  • Format information: modules near the finders that record the error correction level and mask used.
  • Quiet zone: the blank margin around the code, which the scanner needs to see where the code ends.
A QR code cannot infect your phone on its own: it is just text. The risk is where it sends you.

How does your phone read a QR code?

When you point the camera at a code, software looks for the distinctive finder squares, which have a ratio of dark and light bands that is unlikely to appear elsewhere. From the three finders it calculates the code’s position, size and rotation, and corrects for perspective if you are holding the phone at an angle.

It then samples the centre of each module to decide whether it is dark or light, removes the mask pattern that was applied to avoid confusing shapes, and reads the bits in a fixed zigzag order. The bits are decoded into characters and the error correction checks and repairs any mistakes. All of this takes a fraction of a second.

The result is usually text. If the text is a web address, your phone offers to open it. Codes can also hold Wi-Fi login details, contact cards, calendar events or plain text.

Why do QR codes still work when damaged?

QR codes use Reed-Solomon error correction, the same family of maths used on CDs and in deep-space communication. Extra data is added that lets the reader rebuild missing or wrong parts. The person making the code chooses one of four levels, which can recover roughly 7, 15, 25 or 30 percent of the data.

Higher levels make the code more robust but need more modules, so the grid gets denser for the same content. That redundancy is also why some designers can put a small picture in the middle of a code: it covers modules, but the error correction fills them back in. Covering the finder squares, however, usually breaks the code completely.

What is the difference between static and dynamic QR codes?

A static QR code contains the final data directly, such as the full web address. It never expires and works without any service behind it, but you cannot change where it points once printed.

A dynamic QR code contains a short address on a redirect service, which then forwards you to the real destination. The owner can change the destination later and see how many people scanned it. The downside is that the code stops working if the redirect service shuts down or the subscription ends, which can strand printed material.

Are QR codes safe to scan?

A QR code itself cannot run code or infect your phone. It is just text. The risk is where it sends you. Scammers sometimes stick fake codes over real ones on parking meters, posters or restaurant tables, leading to look-alike payment or login pages. This is sometimes called quishing.

The same advice that applies to links in emails applies here. Read the address your phone shows before opening it, and be suspicious of any page that asks for card details, passwords or app downloads.

  • Check the web address preview before tapping it.
  • Look for stickers placed over an original code, especially on parking machines.
  • Do not enter payment details on a page you reached by an unexpected code; use the official app or website instead.
  • Be wary of codes in unexpected letters or emails asking you to log in.
  • Use your phone’s built-in camera scanner rather than a random scanner app.

How do you make a QR code that scans reliably?

If you are creating a code for a poster, a wedding invitation or a shop window, a few simple rules make sure people can scan it. Keep strong contrast, dark on light, and leave a clear margin around the code. Make it large enough for the expected distance; a common rule of thumb is a code width of about a tenth of the scanning distance.

Keep the content short, since a shorter web address gives a less dense, easier-to-scan grid. Always test the printed version with several phones in real lighting before printing hundreds.

Frequently asked questions

Do QR codes expire?

+

Static QR codes never expire because the data is in the pattern itself. Dynamic codes depend on a redirect service, so they stop working if that service ends. The destination page can also be taken down.

Can a QR code give my phone a virus?

+

Scanning a code only reads text. The danger comes from opening a malicious website or downloading something it points to. Check the address before opening, and never install apps from a QR code you do not trust.

Do I need an app to scan QR codes?

+

Most modern phones scan QR codes with the built-in camera app or a scanner in the control panel. Separate scanner apps are rarely needed and some show ads or collect data.

How much data can a QR code hold?

+

The largest QR codes hold a few thousand characters, but most hold far less. In practice codes usually carry a short web address, because the more data a code holds, the denser and harder to scan it becomes.

Why won’t a QR code scan?

+

Common causes are poor lighting, glare, a code that is too small or too far away, low contrast colours, or a missing margin around the code. Clean the camera lens, move closer and hold the phone steady.

Can you share Wi-Fi with a QR code?

+

Yes. A QR code can contain your network name and password in a standard format, and phones will offer to join the network when scanned. Many phones can generate one from the Wi-Fi settings.

A QR code is a tidy grid of bits with corner markers and some clever maths for repairs. Treat it like any link: scan freely, but read where it goes before you tap.

How we research: Guides are written from established sources and checked for accuracy. They are general information, not professional advice.

Written by

Plugpixels Editorial Team

Technology

Our writers have spent years taking devices apart, on the bench and on paper, and explain them in plain language.

More Stories

View all →