How Computers Represent Everything in 0s and 1s
You’ve probably heard at some point that computers only deal with 0s and 1s. But when you actually stop to think about it, it sounds strange. We use computers to write documents, view photos, listen to music, and watch videos. The idea that all of this is really represented by just two digits, 0 and 1, is hard to grasp.
In this post, I’ll explain intuitively how a computer turns completely different kinds of information, like text, numbers, color, and sound, into nothing but 0s and 1s. There’s almost no math involved. Once you get the core idea, it’s a simpler story than you’d expect.
Why 0 and 1 in Particular #
Inside a computer, electricity flows. And the easiest signal to work with is just two states: “electricity is flowing” and “electricity is not flowing.”
Think of a light switch. There are only two options, on and off. If you try to distinguish a vaguely half-lit state, it’s hard to judge where “half” begins and errors creep in. But if you only distinguish on and off, there’s almost nothing to get confused about.
A component inside the computer called a transistor does exactly this job. It’s a tiny switch that either lets electricity flow or blocks it. When you write down this on and off as numbers, you get 1 and 0. So it’s not that computers chose to use 0 and 1. They simply call the two most stable states, on and off, “0” and “1.”
Bits and Bytes #
A single 0 or 1 is called a bit. It’s the smallest unit of information a computer handles.
A single bit represents only two things: 0 or 1. But when you group several bits together, the number of possible cases grows. Group 2 bits and you get four cases: 00, 01, 10, 11. With 3 bits you get eight. Every time you add one bit, the count doubles.
So with n bits, you can represent 2 to the nth power cases. Group 8 bits and you get 2 to the 8th power, which is 256 cases. This group of 8 bits is called 1 byte. Yes, it’s the same byte that comes up when you talk about file sizes.
To sum up: 1 bit is a 0 or a 1, 8 bits make up 1 byte, and 1 byte can distinguish 256 cases. That number, 256, shows up again later, so it’s worth remembering.
Numbers: Binary #
The numbers we normally use rely on ten symbols, from 0 to 9. When you reach 10, you carry over to a new place. This is the decimal system.
A computer uses only two symbols, 0 and 1, so it carries over when it reaches 2. This is the binary system. The principle is identical; only the number of symbols differs.
Let’s look at a simple example. Let’s read the binary number 1011. From the right, the places have values of 1, 2, 4, and 8, and you add up the values of only the places that are switched on. In 1011, from the right we have 1 (on), 2 (off), 4 (on), and 8 (on), so we skip the 2 and add 1, 4, and 8 together. That gives 1 plus 4 plus 8, which is 11. It looks complicated, but in the end it’s just adding up the values of the places that are on.
There’s no need to memorize this deeply. Understanding it at the level of “a computer writes numbers as combinations of 0s and 1s” is enough.
Text: Represented by Agreement #
A question comes up here. Numbers are fine, but how do letters become 0s and 1s?
The answer is an agreement. People decide in advance that “this number means this letter.” This agreement is called encoding.
One of the oldest agreements is ASCII. In ASCII, the capital letter ‘A’ is defined as number 65. ‘B’ is 66, and ‘C’ is 67. So when a computer stores ‘A’, it actually stores the number 65, and that 65 is in turn converted into binary and recorded as 0s and 1s.
The English alphabet and symbols all fit within those 256 cases, so 1 byte was enough. But for scripts with far more characters, like Korean, Chinese characters, and emoji, 256 cases aren’t enough. So a much larger agreement called Unicode was created, assigning a number to nearly every character in the world, and UTF-8 is a way to store those numbers efficiently. The Korean text and emoji we see are mostly handled this way.
In the end, a letter is also a number set by agreement, and a number is once again 0s and 1s.
Color and Sound #
By now you can probably guess how images and music work too — you turn them into numbers the same way.
First, color. A screen is made up of tiny dots called pixels. The color of a single dot is expressed by the intensity of three lights: red, green, and blue. Taking the initials, we call this RGB. Each intensity is written as a number from 0 to 255. If red is 255, green is 0, and blue is 0, you get pure red, and if all three are 255, you get white.
Here too, that 256 from before shows up. From 0 to 255 is exactly 256 cases, so the intensity of one color is recorded in 1 byte. A single photo is millions of such pixels gathered together, so in the end it’s a huge string of numbers.
Sound is similar. Sound is originally a waveform that flows without breaks. The computer chops this waveform into very short intervals and records the height at each moment as a number. This is called sampling. Because it measures tens of thousands of times per second, when you play it back, the human ear hears seamless music. A music file, too, is just a string of numbers.
Wrapping Up #
If I boil down everything we’ve seen into one line, it’s this: to a computer, all the information in the world is ultimately a long string of 0s and 1s.
Text, numbers, the colors in a photo, the waveform of music, all of it gets turned into numbers, and those numbers are in turn written as 0s and 1s. And agreements like “this number is the letter A” or “this number is the intensity of red,” that is, encoding, turn those 0s and 1s back into letters, images, and sound. What looks like magic in a computer is actually the result of these simple agreements stacked layer upon layer.
And the act of instructing a computer on how to handle these 0s and 1s is exactly what programming is. If you’ve been curious about how computers handle information, you’ll likely become curious about programming too — since programming is how you work with that information directly. I’d recommend reading Why Everyone Should Learn Programming next as well.