Everything a computer stores, calculates and sends is ultimately long rows of 0s and 1s. Numbers, text, images, sound and websites are just different ways of interpreting the same bits. Here we explain how the binary number system works, how different kinds of data become bits, and how bits become signals that can be sent over a wire or through the air.
Why only two digits?
A computer is built from billions of transistors, each of which works as a switch: on or off. Two states are easy to tell apart, even when the signal is a little noisy or the voltage fluctuates. If a transistor had to distinguish between ten levels, the slightest disturbance would turn a 6 into a 7. With only two digits, 0 and 1, the electronics are simpler, cheaper and far more reliable, and everything else can be built on top.
How to count in binary
In the decimal system, each place is worth 10 times the place to its right: ones, tens, hundreds. In the binary system, each place is worth 2 times the place to its right: 1, 2, 4, 8, 16, 32, 64, 128 and so on. A binary number is read by adding up the values of the places that hold a 1.
Place value 128 64 32 16 8 4 2 1
Binary 1 0 1 1 0 1 0 1
128 + 32 + 16 + 4 + 1 = 181
The other way, from decimal to binary, can be done by dividing by 2 again and again and noting the remainder each time. Take 13: 13 divided by 2 is 6 remainder 1, 6 gives 3 remainder 0, 3 gives 1 remainder 1, and 1 gives 0 remainder 1. Read from the bottom up, the remainders are 1101, and that’s 13 in binary (8 + 4 + 1).
A single binary digit is called a bit. Eight bits make a byte, which can take 28 = 256 different values, from 0 to 255. That’s why each of the four numbers in an IPv4 address goes from 0 to 255: each of them is one byte. For every bit you add, the number of possible values doubles, so 32 bits give just over four billion, and 64 bits give a number with twenty digits.
Hexadecimal
Long rows of 0s and 1s are hard for people to read, so they’re often written in hexadecimal, the base-16 system with the digits 0–9 and A–F. The point is that one hexadecimal digit corresponds exactly to four bits, so a byte is always two digits: 181 is 1011 0101 in binary and B5 in hexadecimal. You’ll come across hexadecimal numbers in color codes on websites, like #2E7EB8, in MAC addresses and in IPv6 addresses.
Arithmetic and logic
Binary addition works like the kind you learn in school, just with a carry already at 2: 1 + 1 gives 0, carry 1. The whole processor is built from small circuits that perform this kind of operation on many bits at once.
Besides arithmetic, computers use logical operations on bits. AND gives 1 only if both bits are 1, OR gives 1 if at least one of them is, and XOR gives 1 if they’re different. They sound abstract, but they’re used everywhere. A subnet mask in a network is applied with AND to find the network part of an address, and XOR is used in encryption and error checking.
Numbers, text, images and sound
A row of bits means nothing on its own. It’s the agreement about how to interpret them that makes them a number, a letter or a color. The byte 01000001 is the number 65, but in a text file it’s the letter A.
Negative numbers are almost always stored with a method called two’s complement, where the first bit indicates the sign. The method was chosen because ordinary addition then works for both positive and negative numbers without special rules. Decimal numbers are stored as a kind of scientific notation in binary form, which is why 0.1 + 0.2 in many programs gives 0.30000000000000004: 0.1 can’t be written exactly in binary, just as 1/3 can’t be written exactly as a decimal.
Text is stored by giving each character a number. The old ASCII standard had room for 128 characters, enough for the English alphabet, but not for letters like the Danish æ, ø and å. Today Unicode is used, which has numbers for almost every writing system in the world, and on the web it’s almost always stored as UTF-8. There, the English letters still take one byte, while other characters take two, three or four:
| Character | Unicode | UTF-8 (hexadecimal) | Bytes |
|---|---|---|---|
| A | U+0041 | 41 | 1 |
| æ | U+00E6 | C3 A6 | 2 |
| € | U+20AC | E2 82 AC | 3 |
If you’ve ever seen æ instead of æ on a website, it’s exactly those two bytes, C3 A6, being read as if each byte were a character of its own.
Images consist of pixels, and each pixel is usually stored as three bytes, one each for red, green and blue. An uncompressed full HD image (1920 × 1080 pixels) therefore takes up over 6 MB, which is why formats like JPEG, WebP and AVIF compress images. Sound is stored by measuring the sound wave many times a second. A music CD measures 44,100 times a second at 16 bits on two channels, which gives just over 1.4 million bits per second before compression.
From bits to signals
To send bits from one computer to another, they have to be turned into something physical. In a network cable it’s voltage levels, in a fiber connection light pulses, and in Wi-Fi and mobile networks changes in the frequency, strength and phase of radio waves. Modern connections encode several bits in each signal to get more through, and that’s a big part of why speeds keep rising over the same cables and frequencies.
No physical connection is error-free. Noise and interference can flip a bit, turning a 0 into a 1. That’s why extra bits are always sent along that make it possible to detect errors. The simplest form is a parity bit, which says whether the number of 1s should be even or odd. Networks use more advanced checksums, and some connections can even correct errors themselves without asking for the data again. How data is split into packets and sent reliably across the internet, you can read in the guide to packets in TCP/IP, and the overview of all the layers is in the guide to network protocols.
Frequently asked questions
Is a kilobyte 1,000 or 1,024 bytes?
Officially, a kilobyte (kB) is 1,000 bytes, and 1,024 bytes is called a kibibyte (KiB). In practice, kB is still used for both, which is why a hard drive looks smaller in the operating system than on the box.
Why is internet speed measured in bits and files in bytes?
Connections are traditionally measured in bits per second, files in bytes. Divide by 8 to compare: a 100 Mbit/s connection can transfer at most around 12.5 MB per second.