Bits: why computers count in ones and zeros

Beginner5 min readPart 2 of 9

Everything inside a computer is a tiny switch that is on or off. See how ones and zeros can count, and try it with a live binary counter.

Here is a strange fact. Inside a computer there are no numbers, no letters, no pictures and no music. There are only tiny switches, and each one is either on or off. Everything else is built from that.

The switch

Think of a light switch. It has two settings: on and off. Nothing in between.

Inside a computer chip there are billions of microscopic electronic switches called transistors. Each one is on (electricity flows) or off (it does not). We write "on" as 1 and "off" as 0.

One of these 1-or-0 values is called a bit, short for binary digit.

Why only two?

It would be possible to build a machine with ten settings, like our digits 0 to 9. But it would be hard to make every setting reliable. Electricity is a bit messy: voltages wobble, and wires pick up noise.

A switch that is clearly on or clearly off is easy to tell apart, even with some wobble. So computers use two settings, and are very good at never mixing them up.

Counting with only two digits

If you only have 0 and 1, how can you count past 1? The same way we count past 9. When we run out of digits, we add a new column.

In everyday counting, each column is worth 10 times the one on its right: ones, tens, hundreds. In binary, each column is worth 2 times the one on its right: 1, 2, 4, 8, 16, and so on.

To read a binary number, add up the columns that have a 1:

BinaryWorkingNumber
1014 + 0 + 15
1104 + 2 + 06
11018 + 4 + 0 + 113

Try it

Here are eight switches. The number under each switch is what it is worth. Flip them and watch the total.

128
64
32
16
8
4
2
1

0All switches are off, so the number is 0.

Each switch is worth double the one to its right. Add up the switches that are on to get the number.

Try these:

Bits, bytes and storage

Eight bits make one byte. With 8 switches you can make 256 different patterns (from 0 to 255).

Every extra bit doubles the number of patterns you can make: 1 bit gives 2, 2 bits give 4, 3 bits give 8, and 10 bits give 1,024. That doubling is why computers can store such huge amounts with a modest number of switches.

We measure storage in bytes:

UnitAbout how many bytesRoughly what fits
Kilobyte (KB)a thousanda short email
Megabyte (MB)a milliona photo or a song
Gigabyte (GB)a billiona film
Terabyte (TB)a thousand billionthousands of films
Count to 31 on one hand

You have five fingers on a hand. Let each finger be a bit: up is 1, down is 0. The thumb is worth 1, the next finger is 2, then 4, 8, and 16. With one hand you can count from 0 to 31. With two hands, up to 1,023.

What is next?

If everything is bits, how does a computer store a letter, a photo or a song? That is the next lesson.

Words to know

Bit
A single 0 or 1. The smallest piece of information in a computer.
Binary
Counting with only two digits, 0 and 1.
Byte
A group of 8 bits.
Transistor
A tiny electronic switch. A chip has billions of them.

Check yourself

  1. What number is the binary number 1010?

    Show the answer

    8 + 0 + 2 + 0 = 10.

  2. Why do computers use only two settings, on and off?

    Show the answer

    Two settings are easy to tell apart reliably, even when the electricity wobbles a little.

  3. How many different patterns can 3 bits make?

    Show the answer

    8, because each extra bit doubles the number: 2 × 2 × 2.

  4. What is the biggest number you can make with 8 bits?

    Show the answer

    255, which is 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1.