Binary — How Computers Store Everything

How computers use billions of tiny light switches to remember your favourite games, photos, and messages.

Imagine a room with eight light switches. By flipping them on and off in different patterns, you could spell your name, write a song, or even draw a picture! That is exactly how the most powerful computers in the world store everything.

Words to own

Binary
A number system that uses only two digits, 0 and 1, to represent all information.
Bit
A single 0 or 1, which is the absolute smallest piece of data a computer can hold.
Byte
A group of 8 bits side-by-side, which is enough space to store one character of text.
Place value
The value of a column in a number system; in binary, these columns double every time you move left.
ASCII
A standard code book that converts numbers into keyboard letters, like mapping the number 65 to 'A'.
Decimal
Our everyday counting system based on ten digits (0 to 9) and column values that multiply by ten.

The Ultimate Light Switch

Inside your computer's brain is a microchip packed with billions of microscopically tiny pathways. Electricity can either flow through a pathway, or it can be blocked. Because of this, a computer can only ever understand two states: Off and On.

We represent these two states using numbers: 0 for Off, and 1 for On. This is why computers use binary. Since a computer cannot understand the number 2 or 7 directly, it must turn every number, letter, and colour into a pattern of 1s and 0s.

How to Convert the Decimal Number 13 into Binary
  1. Step 1

    Find the biggest column

    Look at the binary columns (128, 64, 32, 16, 8, 4, 2, 1). The largest column that fits inside 13 is 8.

  2. Step 2

    Place your first 1

    Put a 1 in the 8s column. Subtract 8 from 13. You have 5 left over.

  3. Step 3

    Check the 4s column

    Does 4 fit into 5? Yes! Put a 1 in the 4s column. Subtract 4 from 5. You have 1 left over.

  4. Step 4

    Check the 2s column

    Does 2 fit into 1? No, it is too big. Put a 0 in the 2s column.

  5. Step 5

    Check the 1s column

    Does 1 fit into 1? Yes! Put a 1 in the 1s column. You have 0 left. Your binary result is 1101.

Decoding the Columns

In math class, you count in decimal. The columns are 1s, 10s, 100s, and 1000s. Every step to the left multiplies the column value by ten.

In binary, we multiply by two instead! The columns start at 1 on the far right, and double every time you move left: 1, 2, 4, 8, 16, 32, 64, and 128. To read a binary number, simply look at which columns have a '1' (meaning the switch is On) and add those column values together.

Converting binary 1011 to a decimal number in Python
# Tell Python to read '1011' as a base-2 (binary) number
binary_text = "1011"
decimal_number = int(binary_text, 2)
print("Binary 1011 is equal to decimal:", decimal_number)
Output
Binary 1011 is equal to decimal: 11

Writing in Binary

To convert a normal decimal number into binary, we work backwards. Start with the biggest binary column that can fit inside your number without going over. Place a 1 in that column, subtract its value, and look at what is left.

Let's convert 20. The biggest column that fits inside 20 is 16. We write a 1 in the 16s column. We have 4 left over (20 - 16 = 4). The next column is 8, which is too big for 4, so we write a 0. The next column is 4, which fits perfectly! We write a 1 in the 4s column. Now we have 0 left, so we write 0 in the 2s and 1s columns. Our final answer is 10100!

Letting Python convert a decimal number to binary
number = 20
# bin() converts the number, and [2:] chops off Python's binary prefix
binary_version = bin(number)[2:]
print("Decimal 20 in binary is:", binary_version)
Output
Decimal 20 in binary is: 10100

Text, Bits, and Bytes

A single 0 or 1 is called a bit. If you glue eight bits together, you get a byte. One byte is the exact amount of space needed to store a single letter of text on a computer.

But how does a computer turn 0s and 1s into letters? It uses a code book called ASCII. In ASCII, every key on your keyboard has a matching number. For example, the capital letter 'A' is represented by the number 65, which is written in binary as 01000001.

Your turn — run real Python

My Secret Binary Code

Change the age variable to your own age and see it converted into binary, then change it to 65 to see what secret letter of the alphabet is hidden there!

1
2
3
4
5
6
7
8
9
10

Bug hunt

Why does this program crash when trying to convert binary to a decimal number?

# We want to convert the binary string 101 to decimal
# But something is wrong with our int() function arguments!
decimal_val = int(101, 2)
print(decimal_val)

Myth-busting corner

  • MythBinary is a completely different math language that only computer scientists can understand.

    TruthBinary is just counting! Instead of carrying over to a new column at 10, binary columns carry over at 2.

  • MythComputers store actual letters like 'A' and 'B' inside their microchips.

    TruthComputers only store electrical 0s and 1s. They translate those numbers into letters on your screen using ASCII or Unicode.

Exam answer that scores full marks

Convert the binary number 1101 to decimal and explain your method.

To convert the binary number 1101 to decimal, write the place values above the digits from right to left: 1, 2, 4, and 8. Aligning them gives 8 under the first 1, 4 under the second 1, 2 under the 0, and 1 under the final 1. Next, add only the numbers that have a 1 beneath them: 8 + 4 + 0 + 1 = 13. This works because each binary column is worth twice as much as the column to its right, allowing us to build any whole number using only 0s and 1s.

Why it scores

  • Clearly lists the binary place values (8, 4, 2, 1) and aligns them to the digits.
  • Shows the exact addition step (8 + 4 + 0 + 1) to arrive at 13.
  • Explains the underlying logic of binary place values doubling as they move left.