How do Barcodes actually work?


Hey Reader, Happy Wednesday!

Finally, I’m back in California after my hiatus. I got married in November and wanted to take a long break for the first time since I started writing this newsletter 2 years ago. Also, fortunately, the stars and time aligned for me to travel to Vietnam, Thailand, and India during this break. After all the fun and frolic, I thought now was the right time to get back at it and continue the newsletter marathon.

So let's jump in and look at how a barcode you see on every item you buy at the grocery store works this week. I aim to write my newsletter issues in a way that allows one to follow them while traveling on a bus, having coffee, and waiting for food.

How it works: 15-second answer

Barcodes encode data as binary (0s and 1s) using black-and-white lines of varying thickness. A scanner reads these lines and converts them into a 95-digit sequence. The sequence starts and ends with "101" and includes a middle "01010" divider. The remaining digits are grouped into segments: the left side identifies the manufacturer, and the right side identifies the product.

How do Barcodes work?

Dropping some barcode facts first as an appetizer for you.

  1. Over 6 billion barcodes are scanned every day globally.
  2. 91% of the people in the UK have scanned a barcode at least once in their lifetime.
  3. In the U.S., about 89 million smartphone users scanned QR codes.

So naturally, I was super curious to know how it works. So here we go! Now I know how and so do you…

Step 1: Take a picture of the barcode you see at a store

You will see black and white vertical lines of varying thickness as seen in Figure 1. Each white/black line can be x, 2x, 3x, or 4x thick.

And you’ll also find a set of numbers at the bottom, which we will return to later.

Step 2: Take a horizontal slice of the bar code and inspect the black-and-white gaps

Slice the bar code in Figure 1 horizontally and take the strip. You now have a series of black-and-white squares aligned linearly in a row.

Note: We can analyze the bar code further without slicing it horizontally. But it’s easier to follow the explanation seeing it as squares instead of long vertical rectangles.

Step 3: Convert the white and black gaps into 0s and 1s respectively. The longer the width, the more the 0s and 1s.

Starting from left to right, convert the black and white squares to 1s and 0s respectively. The result is a series of 95 digits with just 0s and 1s as seen in Figure 3.

Step 4: Arrange the 0s and 1s into groups

We now have a 95-digit series composed of just 0s and 1s.

Starting from left to right, arrange the numbers into groups as follows.

  1. Left-hand guard pattern: The first three digits in the sequence are always 101 - denoting the start of the barcode.
  2. Left side digits: The next 42 digits are split into 6 groups of 7 digits each as seen in Figure 4. We will see what each of these groups represents in the next section
  3. Center guard pattern: The next 5 digits are always 01010, which denotes the separation between the right and left side digits.
  4. Right side digits: The next 42 digits are split into 6 groups of 7 digits each as seen in Figure 4.
  5. Right-hand guard pattern: The last 3 digits in the sequence are also 101 - denoting the end of the barcode.

Step 5: Find the product code number using the left and right side digits

Take the 42 digits that we split into 6 groups on both the right and left sides of the barcode. Each of these 7-digit groups represents a number between 0-9. Their respective numbers are shown in Figure 5.

Mapping each of the left-side 7-digit groups from Figure 4 gives us the number 51000, which is the company code.

Similarly, the right side digits translate to 01251, which is the product code.

Thus, we can find out who the manufacturer is and what the product is from this barcode. Every item in a grocery store has a unique product code.

So, this is how each product and its manufacturers are uniquely identified.

Source: Code by Charles Petzold.

Question of the week

  1. Why do we need a barcode when we can use the manufacturer and product code numbers (e.g. 51000-01251) directly?
  2. Also, why are the code numbers printed along with the barcode when they both refer to the same thing? Isn’t that redundant information?

Reply to this email with your thoughts, and we’ll have a discussion. Also, I’ll answer this question in the next edition of the newsletter on the 18th of February.

Gadget of the week

Vacuum robot with an arm: The five-axis robot arm unfolds from the top of the vacuum. It can extend and twist, in a bid to remove obstacles from its path and pick up laundry items weighing less than 300 grams. The arm sports an onboard camera and other sensors to orient itself in space. This robot by Roborock was featured in the Consumer Electronics Show 2025.

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 330+ 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! Last week, we went to the Cherry Blossom festival in San Francisco. Let’s look at how the Internet works for the next four weeks, starting today. I aim to write my newsletter issues in a way that 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 Internet is physical and fragile. The YouTube video file is stored on a computer in a building (aka data center) somewhere in the world,...

Hey Reader, Happy Wednesday! Last week, I went to Lake Tahoe in California for the long weekend. Let’s look at how a SOS signal 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 SOS is a universal distress signal used in emergencies. It works through Morse code, which combines short (·) and long (—) signals to form letters and words. The letters SOS...

Hey Reader, Happy Wednesday! Last week, I experimented with preparing Chinese cuisine at home for every meal. Let’s look at how Velcro works this week. I aim to write my newsletter issues so 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 Velcro is a hook-and-loop fastener made of two parts: loops and hooks. When pressed together, the hooks latch onto the loops, creating a secure bond. Pulling them apart...