How Tech Works

How QR Codes Store Information in a Square

Those black-and-white squares pack surprising amounts of data. Here is how a camera reads a QR code and recovers it even when damaged.

Written and reviewed by the Hubrax team · Updated April 24, 2026

Close-up of a black and white QR code
Photograph via Unsplash

You point your phone at a tiny square of black-and-white speckles on a menu or a poster, and a website pops open almost instantly. The pattern looks like random noise, yet it reliably carries a web address, a payment detail, or a few lines of text. So how does a flat grid of squares actually store information, and how does a camera read it even when part of it is scratched or smudged?

A grid where each square is a bit#

At its heart, a QR code is just a grid of small squares, each called a module. Every module is either black or white, and that single choice is the smallest unit of information a computer understands: a bit. By convention, you can think of a black module as a 1 and a white module as a 0.

Strings of these bits build up into bytes, and bytes stand for letters, digits, and symbols, using the same kind of text encoding that powers the rest of computing. So the code is not a picture of your data. It is your data, spelled out in a long ribbon of ones and zeros that has been folded neatly into a square.

A larger square holds more modules, and more modules mean more bits. That is why a code linking to a short web address can be small and chunky, while one storing a long block of text needs to be denser and finer.

The markers that help a camera find its footing#

A camera does not see a tidy grid. It sees a code that might be tilted, far away, lit unevenly, or photographed at an angle. Before reading anything, the software has to find the code and work out its orientation. QR codes include several built-in landmarks that make this possible.

  • Finder patterns. Those three big nested squares in the corners are the giveaway that there is a code present at all. Their distinctive ratio of black to white is rare in ordinary images, so software can spot them quickly.
  • Alignment patterns. Smaller square markers scattered through larger codes help the software correct for distortion when the code is bent or viewed at an angle.
  • Timing patterns. A line of alternating black and white modules runs between the finder patterns, acting like a ruler that tells the software exactly how big each module is.

A useful analogy: the three corner squares are like the corner pieces of a jigsaw puzzle. Find those first, and suddenly you know which way is up and where every other piece belongs.

Reading the data, step by step#

Once the software has locked onto the code, the reading process runs roughly like this:

  1. Locate and align. Find the finder patterns, then straighten and square up the image so the grid sits neatly.
  2. Read the format hints. A reserved strip near the corners tells the reader two important things: how much error correction was used and how the dark and light modules were scrambled.
  3. Unscramble the pattern. QR codes apply a mask, a deliberate flip of certain modules, to avoid big solid blocks that confuse cameras. The reader reverses this mask.
  4. Walk the bits. The reader follows a defined zigzag path through the grid, collecting black-and-white modules into a long stream of bits.
  5. Decode. Those bits are grouped into bytes and translated back into the original text or web address.

All of this happens in well under a second, which is why scanning feels instant.

Why a damaged code still works#

The most impressive part is that you can scratch, smudge, or even tear away a chunk of a QR code and it often still scans. This is not luck. It is designed in, through something called error correction.

When the code is created, it does not store only your data. It also stores extra mathematical check information calculated from that data, using a technique called Reed-Solomon error correction. Think of it like packing a fragile parcel with plenty of padding. If part of the contents is crushed in transit, the padding and the remaining pieces give you enough to rebuild what was lost.

QR codes come in four levels of this protection. At the highest level, the code can lose a large share of its modules and still be recovered, at the cost of needing a denser grid to hold all that extra check data. This is exactly why a logo can sit in the middle of some codes, or why a coffee stain on a flyer rarely stops the scan.

Common misconceptions#

A few myths are worth clearing up:

  • The squares are not random. Every black and white module is precisely placed. The scattered look comes partly from the masking step that breaks up solid regions on purpose.
  • The code does not contain the website itself. It usually holds a short web address. Your phone reads that address, then goes and fetches the actual page over the internet.
  • A QR code is not inherently safe. It is just a way to carry data, so it can carry a link to anything, including a harmful site. The code itself cannot tell you whether the destination is trustworthy.

That last point is worth a brief, honest note. Because a QR code hides its destination behind a pattern, treat scanning an unknown code the same way you would treat clicking an unknown link. Check the address your phone shows before tapping through, especially for anything involving payments or logins. This is general guidance, not security advice tailored to your situation.

Where they turn up#

Once you know what to look for, QR codes are everywhere: restaurant menus, event tickets, product packaging, app downloads, payment terminals, and Wi-Fi network details you can join with a scan. They caught on because they are cheap to print, work on any decent camera, and bridge the gap between something physical in front of you and something digital online.

The takeaway#

A QR code is a grid of black-and-white squares where each square is a single bit of data. Corner markers let a camera find and straighten the code, a defined path turns the squares back into text, and built-in error correction acts like padding so the code survives scratches and smudges. It is a small, sturdy, and surprisingly clever way to hand a computer information using nothing more than ink and a camera.

Theo Lindqvist
Written by
Theo Lindqvist

A former systems engineer, Theo has built and broken enough hardware and software to explain how it actually works — trade-offs included. He tests his claims on real devices and is allergic to marketing speak. He thinks the best technology is the kind you never have to think about.

More from Theo