Unit 1 · Digital Information · Lesson 1.3

When Numbers Break

A computer never has infinite room for a number. Today you find out what happens when it runs out.

Big Idea 2 — Data
1

Where We Are

World Bits Programs Internet Security Big Data Impact

Still in Bits. In 1.1 and 1.2 you learned that any number can be written in binary. That was the good news. This lesson is the fine print: a real computer sets aside a fixed number of bits ahead of time, and a number that needs more than that has nowhere to go.

2

The Hook

2,147,483,647 In December 2014, YouTube announced that the view counter on Gangnam Style had maxed out. Not slowed down — maxed out. The number above was the largest view count the counter could physically hold, and the video had passed it.

YouTube's engineers had to go in and give the counter more bits. So here's the question for today: why that number? It looks random. It isn't. It's one of the most predictable numbers in all of computing, and by the end of this page you'll be able to work it out on paper.

3

The Idea

When a program stores a number, it reserves a set number of bits before it knows what you'll put there — like buying a 4-digit padlock before choosing your combination. That reservation is called fixed-width representation, and it puts a hard ceiling on the value.

Count the possibilities. With 4 bits, each bit is independently 0 or 1, so there are 2×2×2×2 = 16 different patterns. They represent 0 through 15 — sixteen values, but the largest is 15, because you spent one pattern on zero.

With n bits you get 2n patterns, so the values run from 0 to 2n − 1.
BitsPatternsLargest valueIn binary
416151111
825625511111111
1665,53665,5351111…1111
324,294,967,2964,294,967,2951111…1111

Now go back to the hook. YouTube's counter used 32 bits — but look at the table: 32 bits should top out at about 4.29 billion, and the counter broke at about 2.15 billion. Exactly half. Why?

Because that counter also needed to be able to hold negative numbers, so one of the 32 bits was spent recording the sign (+ or −) instead of a value. That leaves 31 bits for the number itself: 231 − 1 = 2,147,483,647. That's the hook number, and now it isn't random.

What the AP exam expects. The exam asks you to reason about how many values n bits can represent and to recognize overflow when you see it — it does not require you to do signed binary arithmetic. So the row you must know cold is the rule above: n bits → 2n patterns → 0 through 2n−1. The sign-bit detail is here only because the real YouTube story doesn't make sense without it.

So what actually happens when you add 1 to the maximum? The bits have nowhere to carry into, so the value silently rolls over to the bottom — often to 0, or in signed systems, to a large negative number. That rollover is integer overflow. Nothing crashes. Nothing warns you. The number is just wrong from that moment on. You're about to watch it happen.

There's a second, sneakier failure. Ask a computer to store one third. In binary, 1/3 doesn't fit in any finite number of bits — the pattern repeats forever, exactly like 0.3333… does in decimal. The computer stores as much as fits and quietly drops the rest. That tiny discarded remainder is a round-off error. One is harmless. Millions, added up, are not.

4

Try It

Pick a width, then hold down +1 and push the counter past its ceiling. Watch what the value does when the bits run out.

Width:
decimal 0  /  max

Everything you just did by hand, Python will do for you — and it will also show you the round-off problem in one line:

# How many values fit in n bits?
print(2 ** 4)         16      # patterns
print(2 ** 4 - 1)     15      # largest value
print(2 ** 31 - 1)    2147483647   # the hook number

# Round-off error, live:
print(0.1 + 0.2)      0.30000000000000004
print(0.1 + 0.2 == 0.3)  False

That last line is worth sitting with. 0.1 + 0.2 == 0.3 is False on essentially every computer on Earth. Not a bug in Python — a consequence of storing 0.1 in a fixed number of bits.

5

Vocabulary

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

fixed-width representation Bits
Storing a value in a set number of bits decided in advance, which caps the largest value that can be held.
integer overflow Bits
The error that occurs when a calculation produces a number too large for its fixed number of bits, causing the stored value to roll over and become wrong.
round-off error Bits
The error introduced when a value needs more bits than are available and the extra precision is discarded — common with fractions and decimals.
6

Check

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

0 of 5 answered
7

Impact Check

Bits have consequences

A broken view counter is funny. These two are not.

Ariane 5, June 1996. Thirty-seven seconds after liftoff, a European rocket carrying four satellites destroyed itself. The cause: a large number describing the rocket's sideways velocity was converted into a variable with too few bits. It overflowed. The guidance system read the garbage value, concluded the rocket was wildly off course, and swerved hard enough to begin breaking apart. Roughly $370 million, gone, because of a number that didn't fit.

Patriot missile battery, February 1991. A system tracked time by repeatedly adding a value that could not be stored exactly in binary. Each addition was off by a vanishingly small amount. The battery had been running about 100 hours, so those tiny errors accumulated into a timing drift of roughly a third of a second — long enough that the system miscalculated where an incoming missile would be. It failed to intercept. Twenty-eight soldiers were killed.

8

Connections

Came from 1.2 — place value told you how to write any number in binary. This lesson added the constraint that makes it real: you only get so many columns.
Returns in Unit 2 — when you meet Python's data types, "how many bits does this hold" stops being trivia and starts being a decision you make.
Returns in Unit 5 — round-off error is one reason real datasets need cleaning before anyone trusts a conclusion drawn from them.
Returns on the exam — overflow and round-off show up as scenario questions in Big Idea 2. You will be asked to identify which of the two caused a described failure. Overflow = too big. Round-off = too precise.