How Computers Work

Bits, Bytes and Binary

Learn how text, photos, sound and programs all reduce to ones and zeros, what bits and bytes are, and how to read a simple binary number.

On this page
  1. Why only two digits
  2. Counting in binary
  3. What a byte is
  4. How text becomes numbers
  5. How colours and pictures become numbers
  6. How sound and video become numbers
  7. How programs become numbers
  8. Why it matters in daily life

Why only two digits

People count in tens, probably because we have ten fingers. A computer’s hardware is built from switches that are either on or off, so the natural way for it to count is with two digits: 0 and 1. This system is called binary, and a single 0 or 1 is called a bit, short for binary digit.

Using two states is practical rather than clever. It is far easier to build circuits that reliably tell “voltage present” from “voltage absent” than circuits that distinguish ten different levels. Small electrical noise rarely turns an “on” into an “off”, so the information stays intact.

Counting in binary

Decimal numbers work by place value. In 345, the 3 stands for three hundreds, the 4 for four tens and the 5 for five ones. Each place is worth ten times the one to its right.

Binary uses the same idea, but each place is worth two times the one to its right: 1, 2, 4, 8, 16, 32, and so on. To read a binary number, add up the place values wherever there is a 1.

Take 1101:

  • the leftmost 1 is in the 8s place, so it adds 8
  • the next 1 is in the 4s place, adding 4
  • the 0 is in the 2s place, adding nothing
  • the final 1 is in the 1s place, adding 1

Together that is 8 + 4 + 1 = 13. So the binary number 1101 means thirteen.

Going the other way, 10 in decimal is 8 + 2, which is 1010 in binary. Each extra bit doubles how many different values you can represent: one bit gives 2 values, two bits give 4, three give 8, and so on.

What a byte is

Computers generally handle bits in groups of eight, and a group of eight bits is called a byte. With eight bits there are 2 multiplied by itself eight times, which is 256 possible patterns, from 00000000 (zero) up to 11111111 (255).

A byte is the standard small unit for describing amounts of data. Larger amounts use prefixes:

Unit Rough size
Kilobyte (KB) about a thousand bytes
Megabyte (MB) about a million bytes
Gigabyte (GB) about a billion bytes
Terabyte (TB) about a trillion bytes

There is a small wrinkle. Some software counts a kilobyte as 1,000 bytes and some as 1,024 (a power of two, which suits binary). The difference is small for tiny files but grows with larger units, which is one reason a drive can look slightly smaller in your operating system than on its box.

Bits and bytes also appear in different places. Storage and file sizes are normally given in bytes, while internet connection speeds are usually quoted in bits per second. A byte is eight bits, so a connection described in megabits per second moves fewer megabytes per second than the headline number may suggest.

How text becomes numbers

Binary only holds numbers, so anything else needs an agreed code that matches numbers to meanings. For text, the long-standing approach is to give each character a number. In a classic table called ASCII, the capital letter A is 65 and B is 66. In binary, 65 is 01000001, which is 64 + 1.

ASCII covers basic English letters, digits and punctuation. Other languages, accented letters and emoji need many more characters, so a larger standard called Unicode assigns numbers to them all. Some characters need more than one byte to store. The principle is the same: a table says which number stands for which symbol, and everyone using the file follows the same table.

How colours and pictures become numbers

An image on a screen is a grid of pixels, and each pixel has a colour. A common way to describe a colour is with three numbers for the amounts of red, green and blue light. If each of the three gets one byte, with values from 0 to 255, then a pixel takes three bytes, and about 16.7 million colour combinations are possible (256 × 256 × 256 = 16,777,216).

That makes it possible to estimate size. A picture 1,920 pixels wide and 1,080 pixels tall has 2,073,600 pixels. At three bytes each, an uncompressed version would be 6,220,800 bytes, a little over 6 megabytes. Real image files are usually much smaller because they use file compression, which finds shortcuts for repeated patterns. The various image formats differ mainly in how they do that.

How sound and video become numbers

Sound is a continuous wave. To store it, a computer measures the height of the wave many thousands of times each second and records each measurement as a number. Played back in order, those numbers recreate a close copy of the original sound. Video is a quick sequence of images plus sound, so it is built from the same ingredients, again usually compressed.

How programs become numbers

Programs are also stored as numbers. A processor understands a set of instructions, each of which is a particular bit pattern. When people write software they use readable languages, and tools translate that into the processor’s patterns. Because a program and a photo are both just bytes, the same file can mean different things depending on who opens it. That is why file extensions exist: they hint at which program should interpret the bytes, and which of the many file formats to expect.

Why it matters in daily life

Knowing about bits and bytes makes a few everyday situations clearer:

  • Storage and file sizes are literally counts of bytes, so it is no surprise that video and high-resolution photos fill a drive faster than documents do.
  • A single flipped bit can corrupt a file or change a letter, which is why computers include checks and why damaged files sometimes fail to open.
  • The same bytes can be a picture, a song or a program depending only on how they are interpreted.

The essential point is simple. There is no separate world of words and pictures inside the machine, only numbers written in bits, and a lot of shared agreements about what the numbers mean.

The complete guide to how computers work

How a Computer Works: From Switches to Screens
Read the guide

Keep exploring

Guides from other topics

All topics →