Binary and Data Representation
Learn to count in binary, convert between binary and decimal, and see how computers store text, colors, images and sound as bits and bytes.
Welcome back!
Step 1 of 14Learn
Why two digits are enough
Inside a computer there are no numbers, letters or pictures, only billions of tiny switches called transistors, each either on or off. Engineers chose two states because electronics are far more reliable when they only need to tell "high voltage" from "low voltage," instead of distinguishing ten different levels.
We write those two states as 1 and 0. A single 0 or 1 is a bit (short for binary digit), the smallest unit of information. A group of 8 bits is a byte.
One bit can represent two possibilities: yes or no, on or off. Two bits give four combinations: 00, 01, 10, 11. Each extra bit doubles the count, so n bits can represent 2n different values:
- 1 bit: 2 values
- 4 bits: 16 values
- 8 bits (1 byte): 256 values
- 16 bits: 65,536 values
- 32 bits: about 4.3 billion values
This doubling explains many numbers you see in computing. A byte can store a whole number from 0 to 255. Old video games used 8-bit color with 256 colors. Early internet addresses used 32 bits, which is why the world eventually ran short of them.
Step 2 of 14Explore
How fast do bits add up?
The curve shows how many different values n bits can represent (2 to the power n). Move the slider to see the count for a specific number of bits.
- Different values with n bits
- 256
- Largest whole number (starting from 0)
- 255
Step 3 of 14Practice · Work it out
How many different values can 10 bits represent?
Step 4 of 14Learn
Counting in base 2
You already know a positional number system: decimal, or base 10. In the number 352, the 3 means 3 hundreds, the 5 means 5 tens and the 2 means 2 ones. Each position is worth 10 times the one to its right: 1, 10, 100, 1000.
Binary is base 2. It works the same way, except each position is worth 2 times the one to its right:
| Position value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Bits of 1011 0110 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 |
Binary to decimal: add up the position values wherever there's a 1. For 10110110: 128 + 32 + 16 + 4 + 2 = 182.
Decimal to binary: work from the largest position value that fits. For 45: 32 fits (13 left), 16 doesn't, 8 fits (5 left), 4 fits (1 left), 2 doesn't, 1 fits. So 45 = 32 + 8 + 4 + 1 = 101101.
Counting up in binary looks like this: 0, 1, 10, 11, 100, 101, 110, 111, 1000. Notice that 10 in binary means two, not ten. Programmers sometimes write 0b in front to make that clear: 0b10 is 2.
Step 5 of 14Try the calculator
Binary to decimal converter
Set each bit to 0 or 1. The leftmost bit is worth 128, the rightmost is worth 1.
- Decimal value
- 65
Step 6 of 14Practice · Work it out
What is the binary number 1101 0011 in decimal?
Step 7 of 14Practice · Fill in the blanks
Fill in the blanks
The decimal number 13 is written in binary, because 13 = 8 + 4 + 1.
Step 8 of 14Learn
Text: every letter is a number
To store text, computers give every character a number. An early standard called ASCII (1960s) used 7 bits to encode 128 characters: English letters, digits, punctuation and control codes. In ASCII, capital A is 65, B is 66, and lowercase a is 97. The space character is 32.
So the word "Hi" is stored as 72 and 105, or in binary 01001000 01101001.
ASCII had no room for é, ñ, Arabic, Hindi, Chinese or emoji. Today's standard, Unicode, assigns a unique number (a code point) to well over 100,000 characters from nearly every writing system, plus symbols and emoji. The first 128 Unicode code points match ASCII, so old English text still works.
Unicode code points are stored using an encoding. The most common on the web is UTF-8, which uses 1 byte for ASCII characters and 2 to 4 bytes for others. That's why a text message full of emoji takes more space than one in plain English letters.
Have you ever seen garbled text like "é" where "é" should be? That happens when bytes written in one encoding are read as another, a reminder that bits mean nothing until you agree how to interpret them.
Step 9 of 14Practice · Choose one
In ASCII, capital A is 65. What number represents capital D?
Step 10 of 14Learn
Colors, images and sound
Colors. Screens mix red, green and blue light. A common scheme stores each color channel in 1 byte (0–255), so one color takes 3 bytes = 24 bits. Pure red is (255, 0, 0); white is (255, 255, 255); black is (0, 0, 0). Web designers write these in hexadecimal, base 16, which packs each byte into two characters: red is #FF0000. With 24 bits there are 224, about 16.7 million possible colors.
Images. A digital image is a grid of pixels, each storing a color. A 1920 × 1080 image has about 2.07 million pixels. At 3 bytes each, that's about 6.2 million bytes (6.2 MB) uncompressed. Formats like JPEG and PNG use compression to shrink files, by finding patterns (PNG, lossless) or discarding details the eye barely notices (JPEG, lossy).
Sound. A microphone produces a continuous wave. To digitize it, the computer measures (samples) the wave's height many times per second. CD audio takes 44,100 samples per second, each stored as a 16-bit number, per channel.
The big lesson: all data is bits plus an agreed interpretation. The same byte, 01000001, could be the number 65, the letter A or part of a pixel's color. Software decides how to read it.
Step 11 of 14Note
Step 12 of 14Practice · Work it out
An uncompressed image is 1000 × 500 pixels, using 3 bytes per pixel. How many bytes does it take?
Step 13 of 14Practice · Diagram
How big is that data? (uncompressed)
Each step on this scale is ten times bigger than the last. This is why images, audio and video are almost always compressed.
Tap the item that is about 3.5 times smaller than one minute of CD audio.
Tap the shape that answers the question, then press Check.
- One ASCII letter
1 byte = 8 bits.
- A 280-character post
About 280 bytes in plain English text.
- A 1000 × 1000 color image
1,000,000 pixels × 3 bytes.
- One minute of CD audio
44,100 samples per second × 2 bytes × 2 channels × 60 seconds.
- One second of 1080p video
1920 × 1080 pixels × 3 bytes × 30 frames.
Step 14 of 14Practice · Match the pairs
Match each kind of data with how it is typically represented.
Tap an answer, then tap the place where it belongs (or drag it there).
- A letter of text
- A color on screen
- A photo
- Music
Lesson complete!