Unit 1 · Digital Information · Lesson 1.5

Images and Color as Bits

A photo is a very long list of numbers. Today you find out exactly how long — and why that number can't be right.

Big Idea 2 — Data

Before this lesson — read on Runestone

Longer than the last few. Enrolled in our Runestone course? Open it from there so your progress counts.

1

Where We Are

People→ Bits→ Programs→ Internet→ Security→ Big Data→ Impact

Still in Bits, and running the same play as 1.4. There, a letter became a number because a table said so. Here, a color becomes three numbers because a standard says so. The move is identical — only the thing being encoded changed. Which is the point: it always works this way.

2

The Hook

36,000,000 Your phone's camera is about 12 megapixels. In a moment you'll work out that storing one of its photos, honestly and completely, takes 36 million bytes — 36 MB.

Now go open your camera roll and look at what a photo actually takes up. Two or three megabytes. Not close. Ten times smaller than the arithmetic says it can possibly be. Nothing was deleted, and the photo still looks fine. So where did 33 megabytes go? Hold that question — you get the answer in 1.8, and you'll have earned it.

3

The Idea

Zoom far enough into any digital image and it stops being a picture. It becomes a grid of tiny solid squares, each one a single flat color. Each square is a pixel, and a photo is nothing but a very long list of them read left to right, top to bottom — the same order you used to encode your 8×8 grid back in 0.2.

So the whole problem reduces to one question: how do you store one color as a number?

RGB. Every color is stored as three numbers — how much red, green, and blue to mix. Each gets one byte, so each runs 0 to 255.

Zero means none of that light; 255 means all of it. All three at zero is black. All three at 255 is white. Crank red to 255 and drop the others to 0 and you get pure red. That is genuinely all there is to it, and you're about to slide the sliders yourself.

Count what that buys. One byte per channel is 8 bits, so three channels is 24 bits per pixel, which by the rule from 1.1 gives 224 = 16,777,216 distinct colors. That's the "16.7 million colors" printed on monitor boxes. It isn't marketing — it's 224, and you can now derive it.

Hexadecimal: shorthand for the same bits

You have seen colors written like #FF8000 and it looked like a code. It's not a code. It's the same three numbers in hexadecimal — base-16, using sixteen symbols: 0–9, then A, B, C, D, E, F for 10 through 15.

Base-16 exists for exactly one reason: 16 = 24, so one hex digit is worth exactly four bits, always, with no arithmetic. That makes hex a clean shorthand for binary — you just chop the bits into groups of four:

one byte of red, three ways

binary   1111 1111
hex        F    F      ← each group of 4 bits is 1 hex digit
decimal   255

#FF8000  =  R FF (255)   G 80 (128)   B 00 (0)   ← orange

Six hex digits, two per channel, in R-G-B order. Nothing new is being stored — it's the same 24 bits, written in a way a human can read at a glance and type without mistakes.

What the AP exam expects. You should recognize hexadecimal and know it is a compact way of writing binary, and you should know RGB stores color as three values. You are not required to convert fluently between hex, binary, and decimal — that is not on the CED. Don't burn study time drilling it. Do know 24 bits per pixel and where 224 comes from.

Now do the arithmetic from the hook

A 12-megapixel camera produces images of about 4000×3000 pixels. Multiply it out:

4000 × 3000            = 12,000,000 pixels
12,000,000 × 3 bytes   = 36,000,000 bytes   ← 3 bytes per pixel: R, G, B
                       = 36 MB
36,000,000 × 8         = 288,000,000 bits

36 MB per photo. A thousand photos would be 36 gigabytes. Your phone holds far more than a thousand photos and has not filled up. Something is very obviously going on, and it isn't in this lesson. That's 1.8.

A note on "MB," since you'll see both. 36,000,000 bytes is 36 MB if a megabyte means 1,000,000 bytes — the definition storage manufacturers and camera specs use. Some operating systems instead show 1 MB = 1,048,576 bytes (220), and by that definition the same file reads as 34.33 MB. Same bytes, two conventions, and nothing in the number tells you which is meant. If that sounds familiar, it's the Mars Climate Orbiter lesson from 1.2 showing up in your file browser.
4

Try It

Zoom until it stops being a picture

Drag the slider to grow the pixels. Click any pixel to read its three numbers.

Pixel size 4px
Click a pixel to inspect it.

Build a color from three numbers

Slide each channel and watch the bits and the hex change together.

RED255
11111111
GREEN128
10000000
BLUE0
00000000
#FF8000

Predict before you slide

Write down your guesses first, then check them with the mixer. No peeking.

1. What color is (255, 255, 0)?   2. What are the three numbers for black?   3. If all three channels are equal, what kind of color do you always get?   4. Which channel do you raise to turn dark blue into light blue?

How big is that photo, really?

Type any dimensions. The 12 MP button loads the hook's numbers.

Try 1920×1080 — a single frame of HD video is about 6.2 MB raw. Video runs at 30 frames a second. Work out one minute of raw video, then go reconsider how a two-hour movie fits on anything at all.

5

Vocabulary

You just used all three of these. Now they get names.

pixel Bits
One square of a single flat color in a digital image. An image is a grid of pixels, stored as a list of their color values.
RGB Bits
A way of representing color as three values — red, green, and blue — each usually stored in one byte, giving a range of 0 to 255 per channel.
hexadecimal Bits
A base-16 number system using the symbols 0–9 and A–F, where each digit represents exactly four bits — a compact way of writing binary.
6

Check

Five questions in AP format. Pick an answer to see feedback immediately.

0 of 5 answered
7

Impact Check

"The camera doesn't lie" had a shelf life

A film photograph was a physical object. Light hit chemicals and changed them, and the negative was evidence that a particular thing had been in front of a particular lens. Altering it meant physically altering an object, and skilled examiners could usually tell.

A digital photograph is 36 million numbers. Changing it means changing numbers, and a changed number is not damaged — it is simply a different number, indistinguishable from one the sensor produced. There is no original to compare against, because every copy is identical (1.1) and the file itself carries no proof of where its values came from (1.2).

This is not new — photos have been staged and retouched since the 1800s — but it changed who can do it and how fast. Newsrooms, courts, and insurers now treat images as claims needing corroboration rather than as evidence that settles a question. That shift is a direct consequence of a design choice you can state in one sentence: store the picture as numbers.

8

Connections

Came from 0.2 — your 8×8 grid of filled and blank squares was a 1-bit image. RGB is the same idea with 24 bits per square instead of one.
Came from 1.4 — identical move. A number means a letter, or a color, entirely because a standard says so.
Next in 1.6 — the sensor had to turn continuous light into whole numbers in the first place. That step has a name and a cost.
Cliffhanger for 1.8 — 36 MB in, 3 MB out, and the picture still looks right. That gap is compression, and it is the best trick in this unit.
← 1.4 Text as Bits