Colors and Images in Binary
Learn how pixels, RGB values and color depth turn pictures into bits, calculate the size of an uncompressed image and see why compression matters.
Welcome back!
Step 1 of 12Learn
Pictures made of numbers
Zoom far into any digital photo and it breaks into tiny squares of solid color called pixels (picture elements). An image is a grid of pixels, and the computer stores a number, or a few numbers, for each one.
The simplest image is black and white: one bit per pixel, 0 for white and 1 for black. A 10 × 10 smiley face needs just 100 bits. Early computer graphics and fax machines worked like this.
To get more shades, use more bits per pixel. This is called color depth or bit depth:
| Bits per pixel | Colors possible |
|---|---|
| 1 | 2 (black and white) |
| 8 | 256 |
| 16 | 65,536 |
| 24 | 16,777,216 |
You've seen this pattern before: n bits give 2n values. Twenty-four-bit color, 8 bits each for red, green and blue, gives over 16.7 million colors, more than the human eye can tell apart in most situations. That's why it's often called true color.
The number of pixels is the resolution, written as width × height. A Full HD screen is 1920 × 1080, just over 2 million pixels. A 12-megapixel phone camera captures about 12 million pixels per photo. More pixels capture finer detail, but each pixel costs bits.
Step 2 of 12Diagram
Inside one 24-bit pixel
- One pixel = 3 bytes
- Red byte, 0-255
- Green byte, 0-255
- Blue byte, 0-255
Step 3 of 12Practice · Work it out
An image format uses 4 bits per pixel. How many different colors can each pixel show?
Step 4 of 12Practice · Diagram
Colors per pixel by bit depth
Tap the depth used for black-and-white only images.
Tap the shape that answers the question, then press Check.
- 1-bit: 2
2
- 4-bit: 16
16
- 8-bit: 256
256
- 16-bit: 65,536
65,536
- 24-bit: 16.7 million
16,777,216
Step 5 of 12Learn
Calculating image size
The size of an uncompressed image is easy to calculate:
size in bits = width × height × bits per pixel
Divide by 8 to get bytes.
Example: a 1920 × 1080 image in 24-bit color.
- Pixels: 1920 × 1080 = 2,073,600
- Bits: 2,073,600 × 24 = 49,766,400 bits
- Bytes: 49,766,400 ÷ 8 = 6,220,800 bytes, about 6.2 MB
That's for a single frame. A video at 30 frames per second would need about 187 MB per second uncompressed. A two-hour movie would be well over a terabyte.
Yet a typical phone photo file is a few megabytes, and a streamed movie uses a few gigabytes. The difference is compression. Lossless formats like PNG find patterns, such as large areas of one color, and store them more efficiently without losing anything. Lossy formats like JPEG and most video formats throw away details the eye barely notices. Compression is why we can store thousands of photos and stream video over ordinary internet connections.
This calculation also explains why doubling an image's width and height makes the uncompressed file four times bigger: the number of pixels is width times height.
Step 6 of 12Try the calculator
Uncompressed image size calculator
- Total pixels
- 2,073,600
- Size in bytes
- 6,220,800
- Size in megabytes (1 MB = 1,000,000 bytes)
- 6.22 MB
Step 7 of 12Practice · Work it out
How many bytes does an uncompressed 100 × 50 image need in 24-bit color?
Step 8 of 12Practice · Chart
Uncompressed 24-bit image sizes
Tap the image whose width and height are both double 1920×1080.
Tap the bar that answers the question, then press Check.
Step 9 of 12Note
Step 10 of 12Learn
Sound and video too
Images aren't the only media made of numbers. Sound is a wave of changing air pressure. A microphone turns it into a changing voltage, and the computer samples that voltage many times per second, storing each measurement as a number.
Two settings control quality:
- Sample rate: how many measurements per second. CD audio uses 44,100 samples per second; higher rates capture higher pitches.
- Bit depth: how many bits per sample. CD audio uses 16 bits, giving 65,536 possible levels, which captures loud and quiet sounds accurately.
Uncompressed CD-quality stereo sound takes 44,100 × 16 × 2 channels = 1,411,200 bits every second, about 1.4 megabits per second. A 3-minute song is about 32 MB uncompressed, which is why compressed formats such as MP3 and AAC, often around a tenth of the size, made portable music players and streaming possible.
Video is a sequence of images, typically 24 to 60 frames per second, plus sound. Video compression is especially clever: since neighboring frames are usually almost identical, it stores the changes from one frame to the next instead of every full frame.
Underneath every one of these, the same idea applies: choose how many bits to use for each measurement, and you've traded quality against size.
Step 11 of 12Diagram
How sound becomes numbers
Tap a shape with to see more.
- Sound wave
- Microphone voltage
- Sample 44,100 times a second
The CD-audio rate.
- 16 bits per sample
65,536 possible levels for each measurement.
- Stream of numbers
Step 12 of 12Practice · Choose one
Doubling both the width and the height of an uncompressed image does what to its file size?
Lesson complete!