How Computers Store Data (Binary)
Discover how computers store everything as binary: bits and bytes, why machines use only 0s and 1s, how numbers, letters, and pictures become code, with examples and a quiz.
Key takeaways
- Computers store everything using only two symbols: 0 and 1, called binary
- A single 0 or 1 is a bit; eight bits make a byte
- Binary works like our number system but uses powers of 2 instead of 10
- Letters, pictures, and sounds are all turned into binary numbers
Everything is numbers
Open a photo, play a song, send a message β to you they feel completely different. But deep inside a computer, they are all the same thing: long strings of 0s and 1s. This system of just two symbols is called binary, and understanding it unlocks how computers really work.
In an earlier lesson you may have learned that a program is a set of instructions a computer follows. Now we'll look at how the computer stores the data those instructions work on.
Why only 0 and 1?
A computer is built from billions of tiny switches. A switch has exactly two states: off or on. There is no "half on." This is the key idea β it is easy and reliable for a machine to tell the difference between off and on, but very hard to tell apart, say, ten different brightness levels without making mistakes.
So engineers gave the two states two symbols:
- Off β 0
- On β 1
Because there are only two symbols, we call it binary ("bi" means two). Everything a computer stores must be built out of these two states. That sounds limiting, but as you'll see, you can represent anything with enough 0s and 1s.
Bits and bytes
Each single 0 or 1 is called a bit, short for binary digit. One bit on its own can only say two things, like yes/no or off/on. That isn't much. So computers group bits together.
Eight bits grouped together make a byte. With 8 bits, you can make 256 different patterns (from 00000000 to 11111111). That's enough to cover every letter, digit, and punctuation mark you might type. Bytes are the basic building block of computer storage, which is why we measure memory in kilobytes, megabytes, and gigabytes β thousands, millions, and billions of bytes.
Counting in binary
Our everyday number system uses ten digits (0β9). It's called base 10, probably because we have ten fingers. Each position in a number is worth ten times the one to its right: ones, tens, hundreds, thousands.
Binary works the same way, but each position is worth two times the one to its right. So instead of ones, tens, and hundreds, the positions are ones, twos, fours, eights, and so on β the powers of 2.
Let's read the binary number 101:
| Position value | 4 | 2 | 1 |
|---|---|---|---|
| Binary digit | 1 | 0 | 1 |
We add up the positions where there is a 1: that's the 4 and the 1. So 101 in binary equals 4 + 0 + 1 = 5.
Here's another, 1101:
| Position value | 8 | 4 | 2 | 1 |
|---|---|---|---|---|
| Binary digit | 1 | 1 | 0 | 1 |
Add the positions with a 1: 8 + 4 + 0 + 1 = 13.
To count up in binary, you do the same thing as in base 10 β when a column "fills up," you carry to the next. Watch the first few numbers:
0 = 0
1 = 1
2 = 10
3 = 11
4 = 100
5 = 101
6 = 110
7 = 111
8 = 1000
Notice how each time we run out of room, a new column appears on the left, just like going from 9 to 10 in normal counting.
Storing letters
Computers store numbers naturally, but how do they store the letter A? The trick is simple: give every letter a number, then store that number in binary.
There's an agreed-upon code for this called ASCII. In ASCII:
- Capital
Ais 65, which in binary is01000001. - Capital
Bis 66 β01000010. - A space is 32 β
00100000.
So the word "HI" is stored as two bytes: H (72) and I (73), or 01001000 01001001. As long as every computer agrees on the same code, they can swap text perfectly. Modern computers use a bigger code called Unicode so they can store every alphabet on Earth, plus emoji π β but the idea is the same: a letter is just a number, and a number is just binary.
Storing pictures and sounds
The same trick stretches to pictures and sounds:
- πΌοΈ Pictures are grids of tiny dots called pixels. Each pixel's colour is stored as numbers β usually how much red, green, and blue it has, each from 0 to 255. Three numbers per pixel, all in binary, and you have a photo.
- π Sounds are stored by measuring the height of a sound wave thousands of times per second and saving each measurement as a number.
Whether it's a selfie, a song, or a sentence, the recipe is always: turn it into numbers, then store the numbers in binary.
The same bits, different meanings
Here's a brain-twister. The byte 01000001 is the number 65, the letter A, and part of a colour, all at once. How does the computer know which one you mean?
It depends on the context the program sets. A word processor reading that byte expects a letter, so it shows "A." A calculator expects a number, so it shows 65. The bits don't change β the program decides how to read them. This is why the same data can be reused in clever ways, and it's also why opening a photo file in a text editor shows nonsense: the program is reading picture bits as if they were letters. Spotting mix-ups like this is a real part of debugging.
Try it yourself
Practise thinking like a computer:
- π’ Convert these binary numbers to normal numbers:
10,110,1001,1111. (Answers: 2, 6, 9, 15.) - βοΈ Write your age in binary. Find the biggest power of 2 that fits, subtract it, and repeat. For example, 12 = 8 + 4, so
1100. - π‘ Try a "binary fingers" trick: each finger is a bit (1, 2, 4, 8, 16...). Raising fingers in the right pattern lets you count past 1,000 on two hands!
- π€ Using ASCII (A = 65, B = 66, ...), work out the number for the first letter of your name, then convert it to binary.
Once you see that everything is just 0s and 1s underneath, the whole digital world starts to make sense β every app, game, and message is binary in disguise.
Quick quiz
Test yourself and earn XP
What two symbols does binary use?
Binary uses only two symbols, 0 and 1, which match a switch being off or on.
How many bits are in one byte?
A byte is a group of 8 bits, enough to store 256 different values.
What is the binary number 101 in our normal counting?
101 means one 4, zero 2s, and one 1: 4 + 0 + 1 = 5.
Why do computers use binary instead of the digits 0-9?
Computer parts are switches that are either off or on, which maps perfectly onto 0 and 1.
How does a computer store the letter A?
Each letter is given a number, and that number is stored in binary. In ASCII, capital A is 65.
FAQ
Computers are built from billions of tiny electronic switches, and a switch can only be in two states: off or on. Those two states match perfectly onto 0 and 1. Building reliable parts that could tell apart ten different levels would be far harder and more error-prone, so two states it is.
It depends on the context set by the program. The same byte can mean the number 65, the letter A, or part of a colour, depending on what the software expects. The program decides how to read the bits, a bit like how the symbols 'I' can mean a letter or the number one depending on where you see them.
Keep exploring
More in Coding