How Does a QR Code Really Work? The Technology Behind the Pixel Mosaic

29.08.2026 9 min Reading time
How Does a QR Code Really Work? The Technology Behind the Pixel Mosaic

A quick scan with your smartphone camera is all it takes—and a website opens, the Wi-Fi connects, or a vCard is saved to your address book. What seems like magic in everyday life is actually an extremely sophisticated combination of computer science, mathematics, and optics.

But how does a long web address or a piece of text actually turn into this distinctive black-and-white pattern? Where is the data hidden in the code, and why does the camera recognize the content even when the QR code is tilted or slightly damaged?

In this article, we’ll break down how the Quick Response (QR) code works step by step.

1. The basic principle is simple: Characters are converted into zeros and ones.

Computers speak binary language, meaning they understand only 0s and 1s. Before information can be represented as a pattern in the QR code, it must therefore first be converted into bits. To save storage space, QR software uses various encoding modes:

  1. Numeric mode: For numbers only (0–9). Very efficient, as three digits are combined into ten bits.
  2. Alphanumeric mode: For digits, uppercase letters, and selected special characters.
  3. Byte mode: For general text, lowercase letters, umlauts (UTF-8), and URLs.
  4. Kanji mode: Specially compressed for Japanese characters.

A look behind the scenes shows how “QR” becomes a binary code.

To understand how space-efficient a QR code is, let’s consider the alphanumeric mode. In this mode, each character is assigned a fixed numerical value (A = 10, B = 11, ..., Q = 26, R = 27).

To avoid having to store each letter individually, the algorithm always combines two characters.

  1. The values of Q (26) and R (27) are calculated: $26 \times 45 + 27 = 1197$.
  2. The number 1197 is represented as an 11-bit binary number: 10010101101.

Thus, the two letters QR result in exactly 11 bits consisting of zeros and ones. If a single letter remains at the end of a string, it is encoded using 6 bits (e.g., $Q \rightarrow 26 \rightarrow 011010$).

2. The Path from Binary Code to the Final Image Pattern

Once your text has been translated into a string of zeros and ones, it goes through several technical processing steps:

[ Your input ] (e.g., “https://qrown.io”)
[ Mode analysis & binary encoding ] (Characters are converted to 0s and 1s)
[ Header & Metadata ] (Information about data length and mode is appended)
[ Error Correction Calculation ] (Reed-Solomon codes are generated)
[ Placement in the Grid ] (Bits are distributed from the bottom right to the top)
[ Masking ] (A mathematical filter prevents disruptive patterns)
[ Finished QR Code ] (Black = 1, White = 0)

Step A: Additional Technical Data and Error Correction

The string of zeros and ones that contains your content isn’t the only part of the code. A header is placed before the payload. This tells the scanner: “Attention, here comes a text in byte mode with a length of 25 characters!”

Next, a mathematical process—known as Reed-Solomon error correction—calculates additional parity bits. These ensure that the code can still be read even if up to 30% of its surface is covered or damaged (e.g., by a company logo placed in the center).

Step B: Distribution in the Grid (Modules)

The individual squares in the QR code are called modules. As a general rule:

  1. 0 = white module
  2. 1 = black module

However, the bits are not simply written in row by row from the top left to the bottom right. Data encoding starts in the bottom right corner and winds its way through the grid in narrow columns of two, alternating between moving up and down. Reserved functional areas (such as the corners) are automatically skipped.

That’s why you can never point to a single black square in the finished QR code and say, “This is the ‘h’ in the web address.”

Step C: The Masking Trick (Why 1 Isn’t Always Black)

If the bits were drawn directly, large black blocks, long white stripes, or misleading patterns could appear at random, confusing the camera.

That’s why the software applies a masking pattern over the matrix. There are a total of eight standardized masks. Using a mathematical XOR operation, the mask inverts certain bits:

  1. 0 becomes 1 (white becomes black)
  2. 1 becomes 0 (black becomes white)

The scanner uses control bits in the header to determine which mask was used and reverses this step in a fraction of a second during decoding.

3. The Anatomy of a QR Code: What Do the Individual Patterns Mean?

If you look at a QR code more closely, it appears to be a random mosaic. In reality, however, every single element is positioned strictly according to the ISO standard. You can think of its structure as the anatomy of a face. Certain features are always in the same place so that a smartphone can recognize the code at a glance.

A classic QR code is divided into the following main zones:

1. The three large corner squares (position detection patterns/finder patterns)

  1. They are located at the top left, top right, and bottom left.
  2. What they do: They are the most striking feature of the QR code. These three anchor points immediately signal to the camera: “Attention, there’s a QR code here!” They instantly tell the software the position, size, and tilt angle, so the camera can detect whether the smartphone is being held straight or at an angle.

2. The dotted connecting lines (timing patterns)

  1. They are located at the bottom right and tell the camera which way is “up” and which way is “down.”
  2. What they do: These lines consist of alternating black and white modules. They function like a ruler for the scanner: Using these points, the software calculates the size of the grid system (ranging from Version 1 with 21 × 21 cells to Version 40 with 177 × 177 cells).

3. The small inner squares (alignment patterns)

  1. They are located in the lower-right area and, in complex codes, distributed throughout the entire pattern.
  2. What they do: These smaller squares serve as digital crosshairs. They help the scanner compensate for distortions, for example, when the QR code is printed on a curved soda can or the flyer has been crumpled.

4. The Control Zone (Format Information)

  1. These are located directly adjacent to the three large corner squares.
  2. What they do: This is where the technical instructions for the scanner are stored. Two crucial pieces of information are encoded in these few pixels: 1. Which error correction level (L, M, Q, or H) is used and which masking pattern was applied to the data.

5. The Invisible Protective Border (Quiet Zone)

  1. This is the completely white, unprinted border surrounding the entire QR code.
  2. Function: To ensure the camera can accurately capture the outer edges of the code, it needs a safety margin away from text, images, or background graphics. This border must be at least four modules (pixel widths) wide. If the quiet zone is missing, the camera will often refuse to scan.

4. What Happens When You Scan a QR Code on Your Smartphone?

When you point your camera at a QR code, the following steps take place in the background:

  1. Search: The camera scans the video image for the three large finder patterns.
  2. Transformation: The software calculates the perspective and digitally “straightens” any image that may have been photographed at an angle.
  3. Unmasking: The grid system reads the format information, recognizes the masking pattern, and removes the mask.
  4. Applying error correction: Any scratches, blurriness, or obstructions are mathematically corrected.
  5. Decoding: The zeros and ones are converted back into readable text, numbers, or control commands according to the mode rules.
  6. Perform action: The smartphone recognizes the data type (e.g., https:// for a URL, WIFI: for login credentials, or BEGIN:VCARD for contacts) and suggests the appropriate app.

Technical Deep Dive: The Most Important Questions Explained

Do you need an internet connection to scan a QR code?

No, not for the scanning process itself. The conversion of pixels into text takes place locally on your smartphone. If the content is plain text, a vCard, or Wi-Fi access credentials, everything works completely offline. Only when the code contains a web address (URL) and you want to open it do you need a data connection.

Is a QR code encrypted?

No. A QR code is merely encoded, not encrypted. Any universal QR code scanner can read the data it contains. Confidential information such as passwords, bank details, or personal PINs should therefore never be stored unprotected in a standard QR code.

Why do some QR codes look much finer and denser than others?

The more data stored directly in the code—for example, a long text compared to a short link—the more modules are required. The code then upgrades to a higher version (from Version 1 with 21 × 21 modules up to Version 40 with 177 × 177 modules).

Static vs. Dynamic: Why Dynamic Codes Stay More Compact

  1. Static QR codes: Store the final destination (e.g., a 150-character-long URL) directly. The pattern becomes very dense and harder to scan.
  2. Dynamic QR codes: Store only an ultra-short redirect link (e.g., qrown.io/12da7). The code remains visually extremely simple and easy to scan, and the actual destination can be changed on the server at any time without having to reprint the code.

Checklist for Functional QR Codes

If you create your own QR codes or have them designed, keep the following basics in mind:

  1. Use short links: Use dynamic QR codes to keep the module density low.
  2. Maintain contrast: Choose a dark pattern on a light background (inverted codes can cause problems for some older cameras).
  3. Observe the margin area: Leave a margin of at least 4 modules from text, cut edges, or graphics.
  4. Adjust error correction: When integrating logos into the code, select at least error correction Level Q or H.

Frequently Asked Questions (FAQ)

How many modules does a QR code consist of?

The smallest QR codes (Version 1) consist of 21 × 21 modules, or 441 cells. The largest version (Version 40) has a grid of 177 × 177 modules, or 31,329 cells.

Can a QR code contain viruses or malware?

A QR code itself contains only text and cannot directly execute malicious program code. However, it can lead to a rigged phishing website or a malicious download. Therefore, always check the domain preview on your smartphone before opening it!

Which mode saves the most space in a QR code?

The most efficient mode is the numeric mode (numbers only), followed by the alphanumeric mode. The byte mode (for general URLs and special characters), on the other hand, requires the most storage space per character.

More posts