Skip to content
PlayOwl
Computers & communication · #326

How do QR codes store information?

Dark and light squares spell out a message that a phone camera can read in a blink.

The big idea: Each little square is dark or light. A row of squares makes a number, each number stands for a letter, and a phone turns the pattern back into words.

Start exploring
0 of 5 parts done
How Things Work poster: How do QR codes store information?
1Watch it

How a square holds a message

  1. Mia finds a QR code on a sign in the park. It looks like a jumble of squares, but her phone can read it. How?
  2. Zoom in. Every little square is either dark or light. Computers call dark a one and light a zero. That one choice is the smallest piece of information there is.
  3. Each letter has a number: A is 1, B is 2 and O is 15. The number is written with five squares worth 16, 8, 4, 2 and 1. For 15, turn on 8, 4, 2 and 1.
  4. Three big corner squares help the phone find the code and tell which way is up. That is why you can scan a code sideways or even upside down.
  5. Extra check squares guard the message. If mud flips one square, a row check and a column check both complain. The square where they cross is the mistake. Flip it back!
  6. The camera snaps the squares, finds the corners, reads every row and fixes any mistakes. In a blink the pattern turns back into words, often a web address.
2Look inside

Look inside a QR code

Tap each part of the code and the phone. Every part has its own job.

  • Corner squares. These three big squares are easy for a camera to spot. They show where the code is and which way is up. The fourth corner has none, so the phone can tell if the code is turned.
  • Timing dots. These squares always go dark, light, dark, light. They work like the marks on a ruler, so the phone can count the rows and columns even if the code is bent or tilted.
  • Message squares. These squares hold the message. In our little code each row is one letter, written as a number with five squares worth 16, 8, 4, 2 and 1.
  • Check squares. Each check square makes the number of dark squares in its row or column even. If a square gets smudged, one row and one column turn odd, and that points straight at the mistake.
  • Quiet border. The empty white edge is called the quiet zone. It keeps the code separate from pictures and words nearby, so the phone can see where the code ends.
  • Phone camera. The camera takes a picture. An app finds the corner squares, checks every little square to see if it is dark or light, and turns the pattern back into letters.
3Try it

Code maker and scanner

Pick a word or tap the message squares to flip them. Watch the phone read the code. Then smudge a square and see what happens.

Experiment: What happens if one square of the code gets smudged?

  1. Pick a word and watch the phone scan it.
  2. Press Smudge a square. Look for the red lights.
  3. See what the phone reads now.

What we found: One smudge is no problem. A row light and a column light both turn red, and the square where they cross is the mistake. The phone flips it back and reads the right word.

Turn on JavaScript to try it yourself.

4Solve a challenge

Code doctor

One square in each code is wrong. Use the red lights to find it, then tap it to flip it back. Fix 3 codes.

5Go deeper

How a QR code stores a message

A QR code is a way to write a message with squares instead of letters. Each little square can only be dark or light. That sounds too simple to say much, but lots of simple choices add up. With five squares you can make 32 different patterns, enough for every letter of the alphabet.

To make a code, a computer turns each letter into a number and each number into a row of dark and light squares. Then it adds three big corner squares, so a camera can find the code and tell which way is up, and a white border to keep it apart from everything around it.

The clever part is the spare squares. They are worked out from the message squares, like a secret sum. If mud, a scratch or a fold spoils a few squares, the sum no longer adds up. The phone can tell which squares are wrong and repair them. That is why a QR code still works when it is crumpled or has a picture printed in the middle.

The little code on this page is a simplified model. A real QR code has at least 21 squares along each side and uses stronger math. A code can lead to any website, so ask a grown-up before you scan one you find on the street.

Key words

Module
One little square of a QR code. It is either dark or light.
Bit
The smallest piece of information: one of two choices, such as dark or light, 1 or 0.
Finder pattern
One of the three big corner squares that help a camera find the code.
Error correction
Spare squares that let a phone repair a code that is dirty or torn.
Parity
Whether a count is even or odd. A parity check adds one square to make the count of dark squares even.
Quiet zone
The empty light border around a QR code.

Check your thinking

  1. What does each little square in a QR code store?

    Show the answer

    One choice: dark or light. A square can only be dark or light. Many squares together make numbers and letters.

  2. Why can a phone read a QR code that is upside down?

    Show the answer

    Three corner squares show which way is up. Only three corners have big squares, so the phone can work out how the code is turned and rotate it.

  3. A code has a muddy smudge on one square, but the phone still reads it. Why?

    Show the answer

    Spare check squares let the phone fix the mistake. The check squares are worked out from the message, so the phone can tell which square is wrong and flip it back.

  4. In our little code, a row shows light, dark, dark, dark, dark. The squares are worth 16, 8, 4, 2 and 1. Which letter number is it?

    Show the answer

    15, the letter O. Add up the dark squares: 8 + 4 + 2 + 1 = 15, and the 15th letter is O.

  5. With parity checks on every row and column, two modules in different rows and columns are flipped. What can the decoder do?

    Show the answer

    Notice that something is wrong, but not tell which modules to fix. Two rows and two columns turn odd. They cross at four modules, and the decoder cannot tell which two of the four were flipped.

  6. You find a QR code on a lamp post and do not know who put it there. What should you do?

    Show the answer

    Ask a grown-up before you scan it. A QR code can open any website. A grown-up can help you check that it is a safe one.