The Science Behind QR Codes

How do QR codes work?


A seemingly simple question, right?  Everyone knows how to use a QR code ― it's as simple as point and scan ― but there's quite literally more to them than meets the eye.  After doing some digging, I discovered that QR codes run off the same principle as your typical "grocery store" barcodes, but with a camera instead of a scanner.  QR codes are more complicated versions of 2D "grocery store" barcodes, which enable them to store over 100x more data than a typical barcode.  Here's some of the science behind QR codes.


When you whip out your phone to scan a QR code on a poster, a lot happens in an instant.  The camera sets itself up to read the QR code through three large squares in the corners plus a smaller square in the last corner, uses several bars of squares to determine formatting, and scans the rest of the space for directions.  I don't understand the scanning process well enough to explain it here, but there's a long list of different scanning algorithms QR codes use.  Not all codes scan the same!



You can see an example of a scanning algorithm above.  Different codes have different algorithms that depend on size and customizability.


I also learned that QR codes can still work if they lose their inner pixels, with some still scannable after even losing 30% of inner pixels.  However, if you go beyond that, your phone will recognize it's viewing a QR code, but won't direct you anywhere on the assumption the code is damaged.  



Try scanning the above image on the right, and you'll find that it won't scan (as your camera reads the QR code data and sees it doesn't go anywhere).


There are even two types of QR codes, static and dynamic.  Static codes will reliable direct you to one website and don't require as many pixels (meaning it'll be easier to scan).  Dynamic codes require more pixels but allow you to change the end destination of the code ― changing the end destination allows you to collect individual user analytics and redirect them accordingly.  With dynamic QR codes, two different users can scan the same code and be directed to two different sites.  Incredible, right?


Interestingly, dozens of "unofficial" QR code variants exist, like JAB codes (which use color and diamond references boxes instead of square ones), IQR codes (somewhat like a rectangular version of square QR codes), and Frame codes (which can be integrated into paintings, backgrounds, and photos to convey information but avoid disrupting the main artwork).   If you're interested in learning more about creating these wacky variants, the MATLAB site has an interesting post on the fundamentals of QR algorithms.



Some QR code variants are shown above.


Even after hours of research, most of the nuance of QR codes is beyond me ― the rabbit hole goes deeper than you'd think.  The hidden complexities of a seemingly simple "point and scan" tool raises interesting questions about other "simple" technologies.  What really happens when we click a button on a website?  How does the mouse scroll wheel work?


I don't know the answer to those questions, but I do know that I won't take "simple" tech for granted again.

RELATED POSTS

The Hexagon Problem

Are Libraries Dying?

Why You Don't Hear About Adult Child Prodigies

Why is Wordle so Successful?

 
Photo Credit:  "QR code" by Christiaan Colen is licensed under CC BY-SA 2.0