The Anatomy of a QR Code: How QR Codes Work

Qr Code Anatomy Decoding Hero

QR codes, like the barcodes they enhance, convey information through a graphical code of black and white pixels. Where a barcode is one-dimensional, a QR code is two-dimensional. In this content it means that information is conveyed by reading both the horizontal and vertical locations of the pixels, rather than simply the horizontal position.

As such, humans can decode parts of a QR code and translate the contents manually, though it is generally tedious and time-consuming. There is generally far more information included in a QR code than the short numerical strings contained in a UPC barcode, meaning human decoding is not necessarily useful or timely.

QR codes can be decoded by any smartphone and dedicated QR scanners and can contain any textual string. This allows web addresses to be encoded in QR codes, which can automatically send the scanning device to the specified URL in the default browser. Unlike barcodes, QR codes also include an error-checking component. This means the QR code can still be successfully decoded even if parts of the code are unreadable.

Common Uses of QR Codes

Qr Code Anatomy Train Ticket Uses

QR codes are robust and durable with greater capacity and reliability than the bar codes they replace. They also improve on magnetic strips, since there’s no risk of demagnetization, and the code can be decoded manually with a reader if necessary.

This has encouraged governmental and non-governmental agencies to adopt QR codes for use on travel documents, passports and licenses, typically duplicating the information in a machine-readable format. QR codes are also widely used in advertising to provide quick links to web assets or app downloads. You can also find QR codes used for payment links, one-time password authentication, Wi-Fi login, and hundreds of other specific applications.

Anatomy of a QR Code

Qr Code Anatomy Overview

The most visually-distinct element of the QR code is the square blocks used for orienting the code when scanned by the reader. This permits the code to be scanned at any orientation, including upside down, and to convey the correct message. These four blocks (three in the corners and one embedded in the lower right) appear in every code and allow the code to be decoded correctly at any orientation.

Around these blocks, format version, error checking version, and decoding mask are encoded. The QR code is surrounded by an area of white space called the “quiet zone” which helps the reader find the edges of the code.

QR codes can come in a range of sizes. The largest QR code, which measures 177 x 177, holds as much as 1,264 characters of ASCII text. The most commonly used size of QR is between 29 x 29 and 33 x 33, which can hold about 50 ASCII characters. All sizes are interoperable with modern reading devices like smartphones.

QR Code Anatomy: Error-Checking and Masking

Qr Format Information

The number of error-checking bits is determined by the enforced error-checking level, called the EDC level. Depending on the EDC level used, different numbers of characters can be recovered if lost or missing. The higher the level of error-checking, the less space left over to contain the message. Most QR code generators will employ the correct level of error correction for the message length and dimensions.

  • L (Low) 7% of characters can be restored.
  • M (Medium) 15% of characters can be restored.
  • Q (Quartile) 25% of characters can be restored.
  • H (High) 30% of characters can be restored.
Qr Code Anatomy Levels Masks

Bits are masked to ensure that the data is expressed efficiently (avoiding all zeros or all ones, for example). This mask is represented as a binary string, which is mathematically combined with the message to produce the QR code. This does not encrypt the message, and the “key” required to decode the masking is included with the QR code.

QR Code Anatomy: Reading QR Codes

Qr Character Placement

The QR code is read from the lower-right corner. Pixels are read as groups of 8, contained one byte per 8 pixels. Depending on how the QR code is encoded, these bit patterns will be linked to different characters. While ASCII is likely the most common encoding, the specification also includes options for numerals, kanji, and other encodings. The four-bit pattern in the lower-right of the QR code (marked “Enc” in the diagram above) determines how the bits will be decoded.

Conclusion

QR codes are tedious to decode manually, but if you know how to read the code, it is technically possible. The flexibility and robustness of QR codes ensures they will remain a popular barcode format for the foreseeable future.

Image credit: Yaohua2000

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Alexander Fox Avatar

Read next

Tristan Harris, Google’s former design ethicist, told the US Senate that the pull-to-refresh gesture on nearly every app works like the lever of a Las Vegas slot machine, and he has long warned that we now reach for our phones around 150 times a day without ever calling it gambling
In 1969, László Bélády and two IBM colleagues published a paging-machine anomaly showing FIFO could make four memory frames suffer ten page faults after three frames suffered nine, leaving generations of operating-systems students staring at the moment more memory became the wrong answer
When Bell Labs engineer Karl Jansky pointed a rotating antenna at the sky in 1932 looking for sources of transatlantic radio static, he kept picking up a faint hiss that peaked every 23 hours and 56 minutes, and he eventually realized he had become the first human to hear the center of the Milky Way.
The colour magenta does not exist anywhere in the spectrum of visible light, and your brain manufactures it on the spot whenever red and blue cones fire together, inventing a hue to fill a gap that physics never bothered to provide.
On 28 May 2009, Google demoed a product called Wave on stage at I/O for 80 minutes and got a standing ovation from developers who had no idea what they had just watched, and 15 months later the company quietly shut it down because almost nobody could explain to a friend what it was actually for
When Clair Patterson set out in 1948 to measure the age of the Earth using lead in meteorites, his samples kept coming back contaminated, and the seven-year detour he took to find the source ended with him almost single-handedly forcing leaded gasoline out of American cars by 1986.
The IBM 305 RAMAC stayed in production until 1961, weighed more than a ton, stored five million characters on fifty spinning platters, and still drew customers because the alternative was a room full of punched cards
In 1977, Ann Druyan recorded an hour of her brainwaves and heartbeat two days after she and Carl Sagan agreed to marry, and NASA pressed the compressed minute onto Voyager’s Golden Record as a private love signal now more than 25 billion kilometres from Earth