Bits, Binary and Digital Data
Discover how bits represent numbers, text, images and sound, how many values n bits can hold, and why overflow and rounding errors happen.
Welcome back!
Step 1 of 10Learn
Everything is bits
Your phone stores photos, songs, messages and maps, yet inside it there's only one kind of thing: bits. A bit (binary digit) is a 0 or a 1, physically stored as something with two states, like a tiny charge that's present or absent. Eight bits make a byte.
How can 0s and 1s mean a song? By agreement. The same sequence of bits can represent a number, a letter, a color or part of a sound, depending on how the program interprets it. The bits 01000001 are the number 65, and in the standard text encoding they're also the capital letter A. Context decides which.
Numbers use the binary (base-2) system. In decimal, each place is worth ten times the place to its right: ones, tens, hundreds. In binary, each place is worth two times: 1, 2, 4, 8, 16, 32, 64, 128.
So 1011 in binary means 8 + 0 + 2 + 1 = 11 in decimal. To convert, add the place values wherever there's a 1.
The key counting rule: with n bits, you can represent 2n different values. One bit gives 2 values, two bits give 4 (00, 01, 10, 11), and 8 bits give 28 = 256 values, from 0 to 255. Every extra bit doubles the number of possibilities.
Step 2 of 10Practice · Work it out
What decimal number does the binary number 110010 represent?
Step 3 of 10Learn
Overflow and rounding errors
Because computers store numbers in a fixed number of bits, there's a limit to what each storage spot can hold.
Overflow. Imagine a counter stored in 4 bits. The biggest value is 1111, which is 15. Add 1 and the true answer, 16, needs a fifth bit (10000). With only four bits available, the extra bit has nowhere to go. Depending on the system, the result might wrap around to 0, or the program might report an overflow error. Old arcade games famously broke when scores or level counters passed their limit. Some languages handle huge whole numbers automatically, but many systems still use fixed sizes for speed.
Rounding errors. Real numbers with decimals are also stored in limited bits, so many of them can only be approximated. Just as one third can't be written exactly in decimal (0.3333...), one tenth can't be written exactly in binary. That's why in many languages 0.1 + 0.2 gives 0.30000000000000004. The tiny error usually doesn't matter, but it can add up over millions of calculations, and it means you should be careful comparing decimals with exact equality.
In the AP framework, the point to remember is: fixed bits mean limited range and limited precision.
Step 4 of 10Practice · True or false
A value stored in 8 bits can represent any whole number from 0 to 256.
Step 5 of 10Learn
Text, images and sound
Text. Every character is assigned a number. The original ASCII standard used 7 bits for 128 characters, enough for English letters, digits and punctuation. Today's Unicode standard covers well over a hundred thousand characters, including every major writing system and emoji, stored in one to four bytes each.
Images. A digital image is a grid of pixels. Each pixel's color is stored as numbers, commonly red, green and blue values from 0 to 255, so one pixel takes 3 bytes. A 1000 by 1000 photo has a million pixels, which is 3 million bytes before compression.
Sound. Sound is an analog signal: a smooth, continuous wave. To store it digitally, the computer samples it, measuring the wave's height thousands of times per second and storing each measurement as a number. CD-quality audio takes 44,100 samples per second. More samples and more bits per sample give a closer copy, but a digital copy is always an approximation of the analog original.
This is a central idea called abstraction: bits are organized into numbers, numbers into colors and samples, and those into photos and songs. Each layer hides the details of the layer beneath it, so a music app can work with songs without thinking about individual bits.
Step 6 of 10Compare
How bits become text, images and sound
| Aspect | Text | Images | Sound |
|---|---|---|---|
| Unit | Character | Pixel | Sample |
| Stored as | A number per character (ASCII, Unicode) | Red, green, blue values 0–255 (3 bytes) | Wave height measured many times a second |
| Example size | 1–4 bytes per Unicode character | 1000 × 1000 photo ≈ 3 million bytes raw | CD audio: 44,100 samples per second |
| Exact copy? | Yes | Yes, of the pixel grid | No, an approximation of the analog wave |
Step 7 of 10Try the calculator
Bits and values calculator
See how many values a number of bits can represent, and how much storage an uncompressed image needs at 3 bytes per pixel.
- Different values with n bits
- 256
- Largest whole number (starting at 0)
- 255
- Uncompressed image size
- 3 MB
Step 8 of 10Practice · Work it out
A school wants to give every one of its 1,500 students a unique ID made of bits. What is the minimum number of bits each ID needs?
Step 9 of 10Note
Step 10 of 10Practice · Choose one
The bits 01000010 are stored in memory. What do they represent?
Lesson complete!