How do QR codes work?


Hey Reader, Happy Thursday!

I went to Michigan for the last long weekend.

Let’s look at how QR codes work this week. I aim to write my newsletter issues in a way one can follow them while traveling on a bus, having a coffee, waiting for food, etc. Let's jump in!

How it works: 15-second answer

A QR code encodes data, such as a URL, into a grid of black and white squares. When scanned by a phone camera, the code is decoded into readable information. Key components include square markers for edge detection, mode indicators for data type, total character count of information to be decoded, the actual encoded data, stop indicators, and error correction data.

How do QR codes work?

QR codes and barcodes essentially do the same thing. The barcode encodes the data linearly using black and white stripes. Whereas, QR codes encode data two-dimensionally using black and white squares.

What is the basic idea behind a QR code?

A QR code encodes a website URL like www [dot] google [dot] com into a series of black and white squares laid out on the square.

So, when we scan the QR code from our phone camera, this URL is decoded by the app by converting the black and white squares into a URL. But how is that possible? Let’s take a very simple example and go over this.

Let’s say we represent the alphabets A, B, and C as a combination of 1s and 0s. And let’s assume that our camera QR code scanner already knows that each alphabet is represented by 4 numbers.

A = 1001
B = 0010
C = 1111

Now if I want to form the word ‘CAB’, then we can write “1111 1001 0010”

If we want to encode this, we can represent this numeric string as a series of black and white squares, where black squares represent the number 0 and the white squares represent the number 1. This is what the word CAB looks like in terms of black and white squares.

Instead of laying it out in a straight line, if we wind it around like we go over the square board on a snake and ladder game, then we have the QR code ready. But there are more components to a QR code than just encoding the URL which we will see in the next section.

Note: The representation we gave for the letters A, B, and C and the way the QR code is generated here is only an example and not the exact method. The original protocol is different. But you get the idea. Now let’s see what are the different components of a QR code and what is it that we are scanning every time.

Different components of a QR code

When you use your phone’s camera to scan a QR code, it first recognizes three square markers at the corners that help it find the edges of the QR code.

All the following information is encoded in the form of black and white squares as we discussed in the previous section.

  1. What is the type of data encoded - Marked as 1 in the figure.
    Starting at the bottom right, the scanner finds the mode indicator, which tells it what type of data is in the QR code (numeric, alphanumeric, etc).
  2. Total number of characters to scan - Marked as 2 in the figure.
    Next, the scanner reads the character count indicator, which tells it how many characters are in the encoded data.
  3. Encoded URL information to be opened - Marked as 3 in the figure.
    With the data type and character length known, the scanner follows a zig-zag path to read all the encoded information until it reaches the end. This has the URL information to be opened in it.
  4. Stop indicator - Marked as 4 in the figure.
    This shows that the encoded data needed to scan the URL is complete.
  5. Error correction data - Marked as 5 in the figure.
    After reading all the data, the scanner checks the error correction data. This data helps recover the information if the QR code is damaged.

These are the components that make a QR code possible. And this is why it works as smoothly as butter, every single time. Now you and I know what we’re getting into the next time we come across a QR code!

Question of the week

What do the green lines around the three corner position marker squares in Figure 3 represent? Reply to this email with your thoughts, and we’ll discuss.

That's all folks. Thank you for reading!

Have an amazing rest of the week, and take care!
Until next to next Wednesday,
Chendur

Enjoying the Newsletter? Choose an option from the poll below so I can work on it. Thanks much!

Read all the past newsletters, about me, or suggest a gadget for me to write about

I'd love to hear what you like about the newsletter. So it'd be cool if you could take a few seconds of your time to share your thoughts :) 🚀

Share this with 1 friend, and Win Rewards!

Have friends who'd love our newsletter too? Give them your unique referral link (below) and get the following rewards when they subscribe.

Refer 1 - Get Behind the Scenes pdf learning about my tools & setup, time management, expenses, etc. in amazing detail!

Refer 3 - I'll give you a shoutout in my email newsletter issue :)

[RH_REFLINK GOES HERE]

Twitter Whatsapp Linkedin

PS: You have referred [RH_TOTREF GOES HERE] people so far

See how many referrals you have

How Do Gadgets Work?

Understand the inner science, tech, and AI of your gadgets with me, a Carnegie Mellon alumnus. Join 205+ readers every other Wednesday to see the world differently in just 3 minutes—regardless of your background! 🚀

Read more from How Do Gadgets Work?

Hey Reader, Happy Wednesday! I'm taking a short break for the first time in the last 2 years of writing this newsletter, so I'm resending one of the most opened and popular newsletters this week. Thank you all for your support! Let’s look at how Airport body scanning technology works this week. It is also called Millimeter wave detection and spot this title written on one of these machines the next time you are at an airport. I aim to write my newsletter issues in a way one can follow them...

Hey Reader, Happy Wednesday! Last week, I finished my swimming classes in India and ‘almost’ learned to swim. Let’s look at how Ships work this week. I aim to write my newsletter issues in a way one can follow them while traveling on a bus, having a coffee, waiting for food, etc. Let's jump in! How it works: 15-second answer Ships float because they are less dense than water. Though made of dense materials like steel, ships have hollow interiors filled with air, reducing their overall...

Hey Reader, Happy Friday! Last week, I came to India to visit my family and friends. I fell sick so I’m sending this newsletter on a Friday instead of the usual Wednesdays. Thank you for the support! Let’s look at how a watch works this week. I aim to write my newsletter issues in a way one can follow them while traveling on a bus, having a coffee, waiting for food, etc. Let's jump in! How it works: 15-second answer A quartz watch uses the piezoelectric effect. A quartz crystal vibrates...