Bits, Bytes, and Everything Is a Number

Table of Contents

  1. Why 0 and 1?
  2. Bits and Bytes
  3. Text Is Numbers
  4. Images Are Numbers
  5. Sound and Video Are Numbers
  6. Programs Are Numbers Too
  7. KB, MB, GB, TB
  8. Try It Yourself

1. Why 0 and 1?

Inside a computer, everything is electricity flowing through billions of tiny switches called transistors. A switch has two reliable states: on or off. Computers write those two states as 1 and 0.

Why not use ten states, like the digits 0–9 we count with? Because telling "on" from "off" is easy and reliable, even when the electrical signal is a bit noisy. Telling ten slightly different voltage levels apart would be fragile and error-prone. Two states is the simplest thing that works every time — and, as you'll see, two states is enough to represent anything.

2. Bits and Bytes

  • A bit (short for binary digit) is a single 0 or 1 — one switch.
  • A byte is a group of 8 bits, like 01000001.

One bit can only be two things. But every extra bit doubles the number of possible patterns:

BitsPossible patterns
12
24
416
8 (one byte)256
1665,536
32about 4.3 billion

So one byte can represent any whole number from 0 to 255. Line up more bytes and you can represent bigger numbers, more precise decimals, and anything else you can agree on a code for.

The arithmetic of binary — converting between binary, decimal, and hexadecimal — is covered properly in Math for Programmers. For this series, you only need the idea: everything is patterns of bits.

3. Text Is Numbers

A computer doesn't know what a letter is. It stores a number for each character, and everyone agrees on the same table of numbers.

The oldest widely used table is ASCII, where for example:

CharacterNumber
A65
B66
a97
0 (the digit)48
space32

So the word Hi is stored as the numbers 72 and 105.

ASCII only covers English letters, digits, and some symbols — 128 characters. To handle every language in the world, including Khmer, modern computers use Unicode. It assigns a number (called a code point) to more than 150,000 characters: Khmer letters like ក, Chinese characters, and even emoji like 🚀. The most common way to store Unicode as bytes is UTF-8, which uses 1 byte for English letters and 2–4 bytes for other characters.

This is why a Khmer message usually takes more bytes than the same length English message — each Khmer character needs 3 bytes in UTF-8.

4. Images Are Numbers

A digital image is a grid of tiny colored dots called pixels. A 1920 × 1080 photo has about 2 million of them.

Each pixel's color is stored as three numbers — how much Red, Green, and Blue light to mix, each from 0 to 255 (one byte each):

ColorRedGreenBlue
Black000
White255255255
Pure red25500
Yellow2552550

If you've ever seen a CSS color like #FF0000, that's exactly this: FF red, 00 green, 00 blue, written in hexadecimal.

Storing 2 million pixels × 3 bytes is about 6 MB for one photo. That's why formats like JPEG and WebP exist — they compress the numbers so the file is much smaller.

5. Sound and Video Are Numbers

Sound is a wave of air pressure. To record it, the computer measures the height of the wave thousands of times per second and stores each measurement as a number. CD-quality audio takes 44,100 measurements per second. Play those numbers back through a speaker fast enough, and you hear the sound again.

Video is just a sequence of images (frames) — typically 30 or 60 per second — plus sound. Uncompressed, that's an enormous amount of data, so video formats like MP4 (H.264) compress it heavily, mostly by only storing what changes between one frame and the next.

6. Programs Are Numbers Too

Here's the surprising part: the instructions a computer follows are numbers as well. "Add these two values" is itself stored as a specific pattern of bits that the CPU recognizes.

That means an app on your computer is, at the lowest level, just a file full of bytes — the same kind of bytes as a photo or a document. The only difference is how they're interpreted. You'll see how the CPU reads those instruction bytes in the next chapter.

7. KB, MB, GB, TB

Because data sizes get large quickly, we use bigger units:

UnitRoughlyReal-world size
Byte (B)8 bitsOne English letter
Kilobyte (KB)1,000 bytesA short text message thread
Megabyte (MB)1,000 KBA phone photo (2–5 MB) or one minute of MP3 music (about 1 MB)
Gigabyte (GB)1,000 MBA movie, or the RAM in a laptop (8–32 GB)
Terabyte (TB)1,000 GBA laptop's whole SSD (0.5–2 TB)

Two confusing things you'll run into:

  • 1,000 vs. 1,024. Some tools count 1 KB as 1,024 bytes (because 1,024 is a power of 2). That's why a "1 TB" drive shows up as about 931 GB on Windows. Nothing is missing — it's just a different way of counting. The 1,024 versions are officially called KiB, MiB, and GiB.
  • Bits vs. bytes. Internet speeds are measured in bits per second (Mbps), with a lowercase b. File sizes use bytes (MB), uppercase B. A 100 Mbps connection downloads about 12.5 MB per second, because 100 ÷ 8 = 12.5.

8. Try It Yourself

  1. Find any photo on your computer and check its size (right-click → Properties on Windows, or Get Info on macOS). Compare the file size with the image dimensions — how much has compression saved compared with width × height × 3 bytes?
  2. Create a text file containing just the word Hello and save it. Check its size — it should be exactly 5 bytes, one per letter.
  3. Now replace the text with a single Khmer word like សួស្តី and save it as UTF-8. Check the size again — it will be several times larger than the number of characters you see.

Every one of those files is the same thing underneath: a sequence of bytes. Next, we'll look at the part of the computer that actually does work with them — the CPU.

Buy Me a Coffee

Found this tutorial helpful? Consider buying me a coffee to support more free content!