Technology

How QR Codes Work: Anatomy, Encoding, and Staying Safe

📷 Leeloo The First · Pexels

✦ Key takeaways

  • The three corner finder patterns let a camera locate and orient the code from any angle.
  • Data is encoded as black and white modules using numeric, alphanumeric, and byte modes with different efficiencies.
  • Reed-Solomon error correction can restore up to 30% of a damaged code at level H.
  • Capacity scales across versions 1 to 40, reaching about 7,089 digits in the largest version.
  • QR phishing (quishing) is a real threat; preview the URL before opening and never enter credentials on a suspicious page.

The square of black and white dots you scan to pay a bill or open a menu might look like random decoration, but it is in fact a precise engineering system that stores information and recovers it even when part of it is damaged. Let us take one apart, layer by layer.

Anatomy: How the Camera Finds Its Way

The most recognizable feature of a QR code is the three large squares in three of its corners, called finder patterns. Each has a fixed module ratio of 1:1:3:1:1, a proportion rarely found in natural images, which lets a camera recognize the code quickly and determine its orientation even when it is upside down or tilted. The missing fourth square in the bottom-right corner is exactly what tells the reader which way is up.

Invoice & Quotation Maker

Professional invoices that auto-calc & print/PDF in a minute.

Learn more · $9

Alongside the finder patterns are smaller but equally vital elements. Alignment patterns are little squares that appear in larger versions to correct distortion when a surface is curved or the image is skewed. Timing patterns are alternating rows of black and white modules that connect the corner squares and establish the coordinate grid for every cell. Finally, the quiet zone is an empty white margin at least four modules wide that surrounds the code to isolate it from visual noise.

How the Data Is Actually Encoded

Each small cell is called a module and represents a single bit: black is 1 and white is 0. Before arranging these modules, the code selects the encoding mode best suited to the content. Numeric mode stores digits only at the highest efficiency, alphanumeric mode covers uppercase letters and a few symbols, byte mode stores any UTF-8 text including Arabic, and a dedicated Kanji mode handles Japanese characters compactly.

After encoding, the bits are split into blocks, error-correction data is appended, and the modules are laid out in the grid following a zigzag pattern that begins at the bottom-right corner. A process called masking then flips certain modules according to a mathematical rule to avoid large clusters of one color, which would otherwise confuse the scanner.

Error Correction: Why a Damaged Code Still Works

The cleverest thing about QR is that it keeps working even when scratched, smudged, or partly covered. Credit goes to the Reed-Solomon algorithm, the same one used on compact discs. It adds redundant data that allows lost modules to be reconstructed, and the designer can choose one of four levels depending on the environment.

Level Recovery capacity Typical use
L (Low) ~7% Clean environments, more data capacity
M (Medium) ~15% The common default
Q (Quartile) ~25% Industrial or dirty settings
H (High) ~30% Product printing or embedding a logo

This is why so many companies can place their logo in the middle of a code; level H tolerates the loss of roughly a third of the modules and still scans. But the higher the correction level, the less room remains for the actual data, so designers balance robustness against capacity.

Versions and Capacity

QR codes come in forty versions, from version 1 at 21x21 modules up to version 40 at 177x177 modules, each version adding four modules per side. A larger version holds more data but is harder to scan from a distance or with a weak camera. At the highest version and lowest correction level, a code can store around 7,089 digits, 4,296 alphanumeric characters, or 2,953 bytes. In practice most links stay short, so relatively small versions are enough.

Take a real example: a 30-character restaurant menu link fits comfortably in a small version such as version 3 at correction level M, small enough to print on a table sticker and scan in under a second.

Safety: Beware QR Phishing (Quishing)

Because the human eye cannot read a QR code, scammers exploit this in an attack known as quishing, sticking a fake code over a genuine one on a parking meter or a poster so it leads you to a page that steals your data or downloads malware. The golden rule is that most camera apps display the URL before opening it; read it carefully and verify the domain name before tapping.

Never enter passwords or card details on a page you reached through a QR code unless you are completely sure of its source, avoid codes stuck up by hand in public places, and enable two-factor authentication on your important accounts so they stay safe even if a password leaks. The code is a powerful neutral tool, and your awareness of it is your first line of defense.

م
Marifa Editorial Team

An independent editorial team that researches trusted sources and reviews every article before publishing for accuracy and clarity. Content is for general educational purposes.

Editorial policy →