QRCODE layout

The "payload" of a QRCODE symbol is a number of data bits followed by ECC parity bits. (See Reed-Solomon calculator) A "version" of QRCODE is selected to be big enough to accommodate this information and a template is created reserving space for formatting and recognition information. The task is to add the data/ecc bit stream to the remaining parts of the symbol (grey modules)
QRCODE version 1 example The diagram on the left shows how version 1 of the QCODE is composed. Version 1 is a square, 21 modules wide and 21 modules high. Version 2 is 25x25, version 3 is 29x29 and so on up to version 40.
Versions 7 and above have version information blocks, to help recoginition software, along with "alignment patterns" in positions defined by the ISO/IEC 18004 International Standard.
QRCODE data strips
Figure 2 below shows how the "strips" are navigated to locate the next "preferred" position. This map visits every module in the symbol excluding all of column 6. However, only modules that do not conflict with formatting information may be used for data bits. QRCODE data strips


6 7
4 5
2 3
0 1
Downwards
When the preferred filling sequence is unencumbered by "formatting furniture", bytes of data appear "folded" into the two bit vertical strip as shown. 7 is the most significant bit, 0 is the least significant. In practice, several modules (bits) from a byte may be displaced around formatting features or moved into adjacent strips. See Figure 3.
Upwards
0 1
2 3
4 5
6 7



This document describes how the data and ecc bits are added to a QRCODE symbol (The ISO standard description is poor).
The task is complicated by the way bytes are folded in attempt to disrupt typical data sequences creating unintended patterns that might confuse symbol recognition software. In fact, after this initial placement is complete, an additional process applies a series of masks in turn, and selects the mask that gives the data part the best random pattern. The mask that was selected is published (twice) in the format information modules.

QRCODE layout overview

Bit Packing Strips. Data is added to the symbol starting in the bottom right hand corner and added bit by bit in vertical strips two bits wide. Figure 1 shows how a number of full height strips may be delineated in a symbol. Note: Column 6 does not contain any valid data positions (in any version) and is excluded. Each "version" increment of the symbol adds an extra 4 modules to the width so, there will always be an even number of strips.

The most significant bit of the data is added to the module at the bottom right hand corner of the symbol. This corresponds to the bottom right position in the rightmost strip. The second bit of the data is added immediately to the left of this module. This process is repeated in a zigzag pattern in the upwards direction.

-X-
  The "preferred" bit placement can be understood by following the path linking all the modules as shown in Figure 2, starting at the bottom right hand corner. If the "preferred" position is not shown as an "available" data position (i.e because it is occupied by QRCODE "formatting furniture" like information modules or functions patterns) the next preferred position along the path is selected and the test is repeated. The full height of symbol is scanned within each two bit strip looking for available data positions before moving on to the next strip.

When there are no futher bit positions available in the strip, the adjacent strip to the left is selected and the search for the next available module position continues in the opposite direction. Packing continues to change direction as available positions are are exhausted in each strip, until every bit of the data/ecc bit sequence has been placed.

For example, to encode 28 data bytes at "M correction level" the symbol must accomodate a total of 44 bytes (28 data bytes + 16 ECC bytes). Figure 3 shows how Version 2 of the symbol is used to place a total of 352 bits.
 R 

The remaining 7 modules in the symbol are coded 0 before masking.
QRCODE layout bit significance