How Are QR Codes and Barcodes Read? The Basics of Encoding

4 min read

Hold a product up at a store register and the price appears with a beep; at a restaurant you scan the QR code on the table to order. These days you even pay with a QR code. What’s inside those stripes and dots, and how does a machine read them?

In this post, I’ll unpack, without any code, how barcodes and QR codes hold information and how they get read.

Barcodes and QR codes are writing for machines #

Barcodes and QR codes are writing made for machines to read, not people. If a person reads numbers off one by one and types them in, it’s slow and error-prone, but written as a pattern, a machine reads it accurately in an instant.

So these patterns aren’t pictures meant to look nice; they’re information transcribed into a form a machine reads well. Beneath registers getting faster and orders getting accurate is this writing.

Stripes and dots hold numbers #

A barcode represents numbers by lining up black and white bars of varying thickness. The bars’ thickness and spacing are, in effect, the numbers. A QR code goes a step further, arranging small black and white cells like a checkerboard. Read the black and white cells as 0s and 1s, and, as covered earlier, a computer can represent information with those 0s and 1s.

A camera or scanner shines on this pattern, reads where it’s black and where it’s white, and unpacks that back into numbers and letters. Where a barcode holds only numbers in a single row, a QR code spreads out across two dimensions and can hold far more information.

A QR code usually holds short information #

Let me clear up a common misconception here. Scan a restaurant’s QR code and the menu appears, but that menu isn’t inside the QR code. A QR code usually holds only short information — for example, a single web address.

What happens the moment you scan is simple: it reads the address written in the QR code and opens that address’s page. The menu is a web page at that address, not the QR code itself. A product barcode is the same: it holds only a product number inside, and the price and name are looked up from the store’s system by that number.

It reads even when a bit messy #

A QR code has one clever device: to stay readable even if part is covered or the print smears, it holds the same information with some overlap. This is called error correction. Thanks to it, even if a corner tears a little or a smudge lands on it, it usually reads fine.

You’ve probably seen a company logo in the middle of a QR code. The reason it still reads even with the center covered by a logo is exactly this error correction. But if too much is covered it can’t read, so there’s a limit to how much you can cover.

So, when you use QR #

When using or making a QR code, a few things are worth checking. First, the habit of confirming where a QR code leads. A QR code of unknown origin is sometimes used to lure you to a fake address, so be especially careful for sensitive things like payment.

When making one, it’s good to allow enough print size and margin. Too small, or packed without margin, and it won’t read well. There’s also a way to keep the same QR code while changing only the address it links to later, so you can update the destination without reprinting.

Why this makes work easier for non-developers #

  • You clear up the misconception. Knowing that a QR code usually holds an address rather than the information itself, you also understand that you don’t need to remake the QR code when you change the menu.
  • You stay security-aware. Knowing a QR code can lead to a fake address, you can advise people not to scan suspicious QR codes carelessly.
  • You make them well. Knowing size, margin, and error correction, you can cut down on mistakes that make them unreadable when you add a logo or put them in print.

Wrapping up #

Today we looked at how barcodes and QR codes are writing for machines, hold numbers in stripes and dots read as 0s and 1s, and usually hold short information like an address. The key distinction is that a QR code doesn’t hold the whole content inside, but an address.

If you’re curious about the basis for the idea that a pattern is read as 0s and 1s, read How Computers Represent Everything in Binary; if you’re curious how a QR-code payment is processed, read How Are Online Payments Processed.

X