ToolBoxOnline
Developer

The Physics of QR Codes How a Grid of Black and White Squares Encodes Information — and Why They Still Work When Damaged

A QR code is a physical encoding of digital information — readable by light, resilient to damage, and scannable from any angle. Here's the physics and mathematics behind the squares.

QR codephysicsencodingerror correctioninformation theory

You scan a QR code on a restaurant table. Your phone camera reads the pattern of black and white squares. In under a second, it decodes the pattern into a URL. The restaurant menu appears on your screen. The QR code just transmitted information from a physical object (a printed sticker) to a digital device (your phone) using nothing but light. No radio waves. No Bluetooth. No WiFi. Just a pattern of squares, a camera, and some elegant mathematics. This is one of the most remarkable and underappreciated technologies in daily life.

How does a grid of black and white squares encode a URL? How does the code still work when 30% of it is damaged? How does your phone read it from any angle? A QR code generator creates the pattern. The physics and mathematics explain how it works. Here is the science behind the squares.

How a QR Code Encodes Information

A QR code (Quick Response code) is a two-dimensional matrix barcode. It encodes information as a grid of black and white "modules" — small squares that represent binary data: black = 1, white = 0 (or vice versa, depending on the encoding). The data is encoded in a specific pattern: finder patterns (the three large squares in the corners — tell the scanner where the code is and what orientation it is in), timing patterns (alternating black and white modules between the finder patterns — tell the scanner the size of each module), alignment patterns (smaller squares that help the scanner correct for distortion when the code is printed on a curved surface), and the data area (the remaining modules — encode the actual information using Reed-Solomon error correction codes).

The encoding process: the data (a URL, text, or other information) is converted to binary, error correction codes are added (redundant data that allows the code to be read even if damaged), the combined data is arranged in the QR code grid, and the finder, timing, and alignment patterns are added. The result is a QR code — a physical encoding of digital information.

How Error Correction Works

Reed-Solomon error correction is the mathematics that makes QR codes resilient to damage. The basic principle: add redundant data so that the original data can be reconstructed even if some of it is lost. The error correction levels: L (Low — 7% recovery. For screen display, where there is no physical damage), M (Medium — 15% recovery. For print on flat surfaces), Q (Quartile — 25% recovery. For products that may get scratched), and H (High — 30% recovery. For harsh environments). Higher error correction = more redundant data = denser QR code = more modules. The trade-off: more recovery vs more visual complexity. The QR code generator handles this automatically. You choose the level. The generator adds the appropriate error correction.

How Your Phone Reads a QR Code

Your phone camera captures the QR code as an image. The QR scanning software: finds the three finder patterns (locates the code in the image and determines its orientation — the code can be read from any angle), uses the timing patterns (determines the module size and grid dimensions), reads the data modules (black=1, white=0 — extracts the binary data), applies Reed-Solomon error correction (reconstructs any damaged or unreadable data), and decodes the binary data into the original text or URL. The entire process takes under a second. The phone just read information encoded as light and dark squares — transmitted from a physical surface to a digital device through the physics of reflected light. The QR code is a bridge between the physical and digital worlds. The physics is the bridge.

Tools mentioned in this article

شارك هذه الأداة