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

When a massive solar storm hit Earth in 1972, it triggered a series of magnetic fluctuations so severe that it accidentally detonated dozens of U.S. Navy sea mines off the coast of North Vietnam, a military mystery that was only classified and explained decades later
In 2020, Philipp Heck’s team dated forty presolar grains from Australia’s Murchison meteorite and found stardust as old as seven billion years, older than the Sun, Earth, and every solid material ever measured on this planet
On 15 September 2017, NASA engineers deliberately steered the Cassini spacecraft into Saturn’s atmosphere at 70,000 miles per hour, not because the mission had failed but because they were terrified of where it might fall if they left it in orbit.
When Konrad Zuse switched on the Z3 in his Berlin workshop in May 1941, he had just built the first programmable computer in history out of roughly 2,000 surplus telephone relays, and almost no one in the world knew it existed because the war buried the story for two decades.
At Kyoto University’s Seto Marine Biological Laboratory on the Shirahama coast, biologist Shin Kubota has watched the same Turritopsis dohrnii jellyfish die and un-die so many times in his tank that he has started writing karaoke songs about an animal that, for all practical purposes, just refuses to stay dead.
In August 1993, Garry Trudeau spent a week turning Apple’s new Newton MessagePad into a Doonesbury joke, including a panel where ‘Catching on?’ became ‘Egg freckles,’ and the $699 handheld never fully outran the punchline
In 1945, Ruth Bourne was one of the young Wrens operating more than 100 Bombe machines at Eastcote, phoning in good stops to Bletchley Park without knowing that Hut 6 codebreakers sometimes cheered on the other end of the line
In 2022, NASA engineers in Pasadena watched a new image come down from Perseverance and saw a small heap of broken rocks resting on the Martian surface in a pattern that looked almost intentional, and the explanation they eventually offered involved a vanished river that has not flowed in three billion years.