QR Basics
5 min read

How Are QR Codes Made? The Mathematical & Step-by-Step Encoding Process

A deep dive into the mathematical and algorithmic pipeline that converts plain text into a scannable 2D matrix according to ISO/IEC 18004 standards.

QR

QRnaly Editorial Team

Published August 14, 2026 • Updated September 8, 2026

The Engineering Behind QR Code Generation

To the naked eye, a QR code looks like a randomized mosaic of black and white pixels. In reality, every single module is placed according to a strict mathematical pipeline defined by the ISO/IEC 18004 specification.

When you type a URL or text into QRnaly, our rendering engine converts your characters into an optical matrix through six deterministic steps.

Step 1: Mode Selection & Data Analysis

The generator analyzes your input characters and chooses the optimal encoding mode to minimize payload bit length:

Numeric Mode (0–9): 10 bits per 3 digits (highest density).
Alphanumeric Mode (0–9, A–Z, $%*+-./: space): 11 bits per 2 characters.
Byte Mode (ISO-8859-1 or UTF-8): 8 bits per character (used for website URLs and international text).
Kanji Mode (Shift JIS): 13 bits per double-byte character.

Step 2: Version Grid & Capacity Sizing

QR codes span 40 standard Versions. Version 1 is a 21×21 module grid, and each subsequent version adds 4 modules per side (up to Version 40, which measures 177×177 modules). The generator selects the smallest version that can hold both your data payload and the requested error correction codewords.

Step 3: Generating Reed-Solomon Parity Bytes

The data bits are divided into 8-bit codewords. The generator then applies Galois Field arithmetic ($GF(2^8)$) and polynomial division using a predetermined generator polynomial to compute Reed-Solomon error correction codewords.

These parity codewords ensure that if a QR code printed on physical paper suffers scratches, folds, or coffee stains, the camera algorithm can mathematically reconstruct the missing data.

Step 4: Placing Structural Markers and Interleaving

The generator places all reserved structural elements:

1.Three 7×7 module Finder Patterns with 1-module separators.
2.Alignment Patterns based on the version coordinates table.
3.Continuous alternating Timing Tracks along row 6 and column 6.
4.Dark Module coordinate $(4 \times \text{Version} + 9, 8)$.
5.Interleaved data and error correction codewords in 2-module wide vertical columns sweeping right to left in a zigzag pattern.

Step 5: Applying the Best Mask Pattern

If data contains large contiguous blocks of dark or light modules, camera sensors struggle to maintain synchronization. To prevent this, QR specifications define eight standard mask formulas (such as $(row + column) \pmod 2 == 0$).

The generator evaluates all 8 mask patterns, scores each against four penalty conditions (consecutive same-color lines, 2×2 solid blocks, 1:1:3:1:1 lookalike patterns, and overall black/white ratio imbalance), and selects the mask with the lowest penalty score.

Step 6: Formatting and Export Rendering

Finally, 15 format bits (error correction level + selected mask pattern + BCH error correction) are inscribed adjacent to the finder eyes. The matrix is converted into vector SVG path geometries or raster canvas pixels for download.

Create Standards-Compliant QR Codes

Experience high-performance, deterministic QR generation with instant vector SVG and PNG export at QRnaly.

Try This In Practice

Generate a Free URL / Link QR Code Now

Create instant high-resolution PNG & vector SVG files in 1 click. Basic static QR codes are available at no cost with no signup required.

Create URL / Link QR

Related QR Guides & Tutorials