Lesson 3 of 6 · 8 min · 2 hands-on steps

Binary: How Computers Count

Flip real bits and see why everything in a computer is 0s and 1s.

Everything is switches

Inside every chip are billions of tiny switches called transistors. Each one is either off (0) or on (1). One switch is called a bit.

One bit can only say two things. Put bits side by side and they can count, just like digits do in normal numbers.

Try it: click the bits

🔢 Click the bits

Binary 00000000 = 0 in decimal

Each bit is worth double the one to its right. 8 bits can store 0 to 255.

Each bit is worth double the bit to its right. Turn on bits until you make 5, then 10, then 255.

How to read binary

In everyday decimal numbers, each place is worth 10× the one to its right (ones, tens, hundreds). In binary, each place is worth 2×: 1, 2, 4, 8, 16, 32, 64, 128.

Binary Math Decimal
0001 1 1
0011 2 + 1 3
0101 4 + 1 5
1010 8 + 2 10

Code can write binary directly. Press Run on this example, then change the numbers and run it again:

JavaScript · try it
Loading…

Why you care

  • 8 bits = 1 byte. File sizes (KB, MB, GB) are counted in bytes.
  • Letters are numbers too: "A" is stored as 65. Emojis use several bytes.
  • You'll almost never write binary at work, but knowing that everything is numbers underneath makes a lot of programming click later.

🧪 Practice: 2 steps

0 / 2 done

Step 1 of 2 · Make the number 5

In code, you can write binary numbers by starting with 0b. For example 0b11 is 3.

Change 0b0 so the program prints 5. (Use the bit visual above: which bits add up to 5?)

JavaScript
Loading editor…

Output appears here. Press Run or Ctrl/⌘ + Enter.

✅ Check your understanding

  1. What is 0b1000 in decimal?

  2. Why do computers use binary?

Create a free account to track your progress.