A computer never has infinite room for a number. Today you find out what happens when it runs out.
Big Idea 2 — DataStill 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.
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.
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.
| Bits | Patterns | Largest value | In binary |
|---|---|---|---|
| 4 | 16 | 15 | 1111 |
| 8 | 256 | 255 | 11111111 |
| 16 | 65,536 | 65,535 | 1111…1111 |
| 32 | 4,294,967,296 | 4,294,967,295 | 1111…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.
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.
Pick a width, then hold down +1 and push the counter past its ceiling. Watch what the value does when the bits run out.
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.
You just used all three of these. Now they get names.
Five questions in AP format. Pick an answer to see feedback immediately.
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.