Codeword
A codeword is the fundamental data unit inside a QR code - a fixed-length block of 8 bits (1 byte). After input data is converted to a bit stream according to the encoding mode, it is divided into 8-bit segments to form data codewords. Reed-Solomon error correction codewords are then calculated and appended, and the complete sequence is arranged into the module pattern.
The total number of codewords is determined by the QR code's version (size) and error correction level. For example, Version 1 (21×21 modules) at error correction level L has 26 total codewords: 19 for data and 7 for error correction. Version 40 (177×177 modules) at level L reaches 3,706 total codewords.
Understanding codewords explains why raising the error correction level reduces data capacity. The total codeword count stays the same, but a larger proportion is allocated to error correction, leaving fewer codewords for actual data. This knowledge helps optimize the balance between QR code size and data volume.
Data codewords vs error correction codewords
Codewords fall into two roles. Data codewords are the input string itself, converted to a bit stream and divided into 8-bit blocks - the payload the QR code carries. Error correction codewords are redundant recovery data calculated from the data codewords with Reed-Solomon coding, allowing the content to be restored even when dirt or damage makes some modules unreadable. During scanning, the decoder first uses the error correction codewords to detect and repair corruption, then decodes the data codewords back into the original string.
How do codewords determine the capacity tables?
The capacity figures in generator specification tables (how many digits or characters fit in version X) are all derived from the data codeword count. For example, Version 1 at level L has 19 data codewords = 152 bits; subtract the mode indicator and character count indicator, then divide the rest by each mode's bits per character (10/3 bits in Numeric Mode, 5.5 in Alphanumeric Mode, 8 in Byte Mode), and you arrive at the same numbers the capacity tables show. The terminator appended to the end of the encoded bit stream and the remainder bits that fill the leftover modules after placement are neighboring concepts in this same mechanism.