Numberwise

Guide

Powers of two, and why computers are full of them

Why 256, 1024 and 65,536 turn up everywhere in computing, what a bit width actually limits, and why the storage on a disk never matches the number on the box.

One wire, two states

A single wire carrying a signal can be in one of two conditions: current or no current. That is the whole of it. Everything else in computing is built by putting more wires side by side, and each wire you add doubles the number of distinct patterns the group can be in.

Two wires give four patterns, three give eight, eight give 256. The sequence is not a convention anybody chose — it is what counting in twos does. When you see 256, 1024 or 65,536 in a specification, you are almost always looking at the number of patterns some fixed group of wires can hold.

This is why the round numbers of computing look nothing like the round numbers of everyday life. A thousand is round because we have ten fingers. A thousand and twenty-four is round because ten wires have that many states.

What a bit width limits

A width in bits sets a ceiling, and the ceiling is one less than the count of values — because one of the patterns has to represent zero. Eight bits hold 256 values, and the largest is 255. That off-by-one is the single most common source of confusion about these numbers, and it is why a colour channel runs 0 to 255 rather than 1 to 256.

The ceilings matter because passing one does not produce an error; it produces a wrong answer. A counter at its maximum does not stop, it wraps to zero.

What each width holds

WidthLargest valueWhy it matters
8-bit255One colour channel, and one byte. Full intensity in a web colour is this number, not 256.
10-bit1,023What high-dynamic-range video gives each channel, against eight bits for ordinary images.
16-bit signed32,767The ceiling every 16-bit field shares, and a familiar cap in older game scores and inventories.
16-bit unsigned65,535The highest port number, and the largest value a two-byte field can hold.
32-bit signed2,147,483,647The limit a great deal of software still carries, and the one that runs out for Unix time in 2038.

Each row is not a little larger than the one above it but 256 times larger. Thirty-two bits is not four times sixteen bits — it is sixty-five thousand times.

Why the disk is smaller than the box says

A drive sold as one terabyte holds a trillion bytes, because the manufacturer uses the ordinary meaning of tera. An operating system that reports in powers of two divides by 1,024 three times instead of 1,000 three times, and reports about 931 of its gigabytes.

Nothing is missing and nobody is lying. The two answers count the same bytes in different units, and the gap widens at every step up the scale — about 2.4 per cent at kilobytes, about 10 per cent by terabytes.

The two kinds of kilo

StepPower of tenPower of two
kilo1,000The SI prefix, and what a drive manufacturer means.
kibi1,024Two to the tenth, and what an operating system usually means when it says KB.
mebi1,048,576Two to the twentieth. The gap against a million has grown to about 4.9 per cent.

The difference compounds. At the kilobyte it is small enough to ignore, and by the terabyte it is most of a missing 69 gigabytes.

Numbers in this guide

Related topics