How do QR codes work?


How do QR codes work?

This question came from a reader submission (thanks Nathan!). Has a curious question stumped you lately? Feel free to submit your own question here:
​

​
πŸ““ The short answer

A QR code is a binary message your camera can read. The grid of black and white squares encodes data, while built-in structural markers tell the scanner how to orient the code, how it's formatted, and how to reconstruct any missing pieces.

πŸ“š The long answer

Back in the 1990s, Masahiro Hara and his team at Denso Wave were tasked with creating a new system for labeling automobile parts. The main drawback of the standard barcode system was that it could only represent ~20 alphanumeric characters. Car parts ended up with multiple labels, forcing employees to scan hundreds of barcodes every day.

Inspired by the design of the Go board, Hara went on to invent the QR code, and Denso Wave later waived patent rights for standardized QR Codes. Hara and his team not only made a superior automobile part inventory system, but also created one of the most widely used data tools in the world.

What is a QR code?

A QR (Quick Response) code is a grid of black and white squares that a scanner can interpret as bits using image processing, with black squares representing "1" and white squares "0."

QR codes have a lot of advantages: they can be scanned from any direction, hold much more data than a traditional barcode, and can even still work with up to 30% of the code being damaged.

It's important to note that a QR code only stores encoded data. The device that reads the data recognizes what kind of content it is, and then decides what action to offer, like opening a URL, saving a contact, or joining Wi-Fi.

What are the different parts of a QR code?

A QR code may look like a random assortment of black and white squares, but there's a method to the madness. Here's a labeled image of QR code of todayyoushouldknow.com as an example.

Each section of the QR code serves a distinct purpose: to help align the scanner, communicate the type and content of data, and add redundancies for error correction.

Finder Patterns

Likely the most recognizable element of a QR code's design, the three squares on a QR code are the finder patterns. The fourth corner is intentionally left empty to tell a scanner which way is "up." The QR code must be surrounded by a blank "quiet zone" to help scanners detect the finder patterns.

Timing Pattern

The timing pattern is a row and column of alternating black and white modules (squares that make up the QR code). It helps the scanner determine the size of each module.

Alignment Pattern

Depending on the size of the QR code, you may find one or more smaller squares in the design. These smaller squares, known as alignment patterns, help the scanner correct for distortion if the code is scanned at an angle or if the code is on a curved surface.

Format Information

Format information tells the scanner key information about how the QR code is encoded. It contains the mask pattern and error correction level.

A mask pattern is a rule that tells the QR code to flip certain modules from black to white, or vice versa. This helps break up large blocks, stripes, or other patterns that could make the code harder for a scanner to read. The code also includes which mask was used, so the scanner can reverse it and recover the original data correctly.

Error Correction

Depending on the level, error correction allows a QR code to still be read even if up to 30% of it is damaged or missing. This is how you often see QR codes with logos smack dab in the middle.

In basic terms, error correction adds backup data so a scanner can still recover data if it's damaged, blurry, or obscured. It uses a method called Reed-Solomon error correction, carefully calculated redundant data so the scanner can detect and reconstruct missing or corrupted pieces. If you want to dig into the math behind it, Veritasium has a great video on it.

Data Content

The bulk of the QR code is devoted to the actual data content being stored. The bits start in the bottom right corner and zig-zag upward in two-column strips until the entire data region is filled.

Here's an example of how you'd encode "Hi" into a QR code using binary:

The first four data bits, in the bottom right of the QR code, tell the scanner how to interpret the following modules, or bits. In this example, 0100 means byte mode. The next 8 modules communicate how much data will follow. And then the remaining modules contain the actual data.

πŸ€³πŸ»β›Άπ–£― Other interesting QR code questions

​
How much data can a QR code contain?

QR codes come in different sizes, or versions, which determine how much data it can store. The smallest version, Version 1, is a 21x21 grid (21Β² = 441 modules). Each subsequent version adds 4 rows and 4 columns, with a maximum size of Version 40 with a 177x177 grid (177Β² = 31,329 modules).

The maximum capacity a QR code can hold is roughly 3 KB of data. To put that into perspective, I could fit all the text of this Today You Should Know article into a single QR code.

How many QR codes can there be?

While there is a finite number of QR codes, practically speaking we will never run out of QR codes.

The maximum capacity the largest QR code (Version 40) can encode is 23,624 bits of data. Since each bit can be either 1 or 0, the total possible number of unique QR codes is 2²³˒⁢²⁴. I'd type out the full number for you, but 2²³˒⁢²⁴ has 7,112 digits. For comparison, 1 trillion has only 13 digits.

Ironically, that 7,112-digit number could not fit inside a single QR code, as they can only hold a maximum of 7,089 digits.

What are some of the most unique QR codes?

Okay, I just wrote that question because I wanted to share some of the cool QR codes I found in my research. Behold:

---

Thanks for reading this week's newsletter! If you have any thoughts, questions, or favorite GIFs, my inbox is always open. Just hit reply to send me a note! :)
​

All my best,

​

​Sources for this week's newsletter​



🌐 Wikipedia article of the week

​Union of Conscientiously Work-Shy Elements​

"The Union of Conscientiously Work-Shy Elements was an unusually successful frivolous political party in Denmark.... Comedian Jacob Haugaard...was very unexpectedly elected to the Folketing with 23,253 personal votes, thereby winning a constituency seat (a locally based seat in parliament).

He made the following promises in the 1994 election (abbreviated list):

  • Tail winds on all cycle paths
  • Better weather
  • Better Christmas presents
  • More whales in the fjord of Randers
  • More Renaissance furniture in IKEA
  • *Nutella in army field rations
  • *The placing of a public toilet in the park in Aarhus where he spent his state party funding on serving beer and sausages to his voters after each election.
  • *More bread for the ducks in parks"

*indicates promises that were fulfilled during his term in office


πŸ“š Did you know all affiliate revenue from book purchases is donated to charity?

Today You Should Know is an affiliate for Bookshop, an online book marketplace that supports local, independent bookstores.

I frequently update the Today You Should Know recommended reading list with my favorite fiction and nonfiction books. And I donate all affiliate proceeds to Room to Read, a leading nonprofit for children's literacy and girls' education across Asia and Africa.

It's a win-win-win: you get to read a book, small bookstores get some business, and money is donated to a great cause.
​

πŸ“• Latest addition: Money for Couples by Ramit Sethi


πŸ‘€ Catch up on other curious questions

P.S. πŸ€” Do you have a question for the newsletter? Click here to submit your question (or reply to this email!)


Refer friends, earn rewards!

Have a curious friend who'd love to learn more about the world? Share the link below and you'll receive rewards for referring people to Today You Should Know.

πŸ“§ (1) Refer just ONE person and receive a special "Five Fast Facts" edition of the newsletter.

πŸ“£ (5) Refer five people and I will shout you out in the newsletter.

πŸ“š (10) Refer 10 people and I will ship you a free, surprise book on an interesting topic.

Thanks for spreading the word!

[RH_REFLINK GOES HERE]

facebook twitter linkedin email

P.S. You have referred [RH_TOTREF GOES HERE] people so far.

πŸ’‘ Today You Should Know

Learn something new every Friday. Join 2,000+ nerds and satisfy your curiosity one question at a time with topics including science, technology, history, and more.

Read more from πŸ’‘ Today You Should Know
Contact lens.

How do contact lenses work? This question came from a reader submission (thanks anonymous!). Has a curious question stumped you lately? Feel free to submit your own question here: Submit your question πŸ““ The short answer Contact lenses correct refractive errors, like nearsightedness, farsightedness, and astigmatism, by using precisely shaped lenses to bend incoming light so it lands on the retina instead of in front of or behind it. πŸ“š The long answer As someone with a mild aversion to putting...

a bird on a tree

Why do nuthatch birds walk upside down? This question came from a reader submission (thanks Nancy!). Has a curious question stumped you lately? Feel free to submit your own question here: Submit your question πŸ““ The short answer Nuthatches climb down trees headfirst to forage more efficiently. By approaching the bark from above, they can spot hidden food that upward-climbing birds may miss. πŸ“š The long answer Say hello to the nuthatch. πŸ™ƒπŸ‘‹ "Sitta-carolinensis-001" by Mdf is licensed under CC...

brown brain decor in selective-focus photography

Can the brain heal itself after a stroke? This question came from a reader submission (thanks Aunt Genie!). Has a curious question stumped you lately? Feel free to submit your own question here: Submit your question πŸ““ The short answer After a stroke, the brain can reorganize its neural pathways to recover lost functions through neuroplasticity. The best way to promote healing is consistent practice of the affected functions, like deliberately using the weaker side of the body for everyday...