A group of n bits can make 2n different patterns. That single rule tells you how many numbers, characters or colours a given number of bits can represent, and how many bits you need for a given set of items.
This lesson ties together binary conversion, the limit behind overflow and the code sizes in character encoding. It closes Representing numbers and text.
Why does each extra bit double the number of values?
Start small and list every pattern.
| Bits | Patterns | Count |
|---|---|---|
| 1 | 0, 1 | 2 |
| 2 | 00, 01, 10, 11 | 4 |
| 3 | 000, 001, 010, 011, 100, 101, 110, 111 | 8 |
| 4 | the 8 patterns above with a 0 in front, plus the same 8 with a 1 in front | 16 |
Adding one bit gives every old pattern two versions: one ending in 0 and one ending in 1. So the count doubles each time: 2, 4, 8, 16, 32, 64, 128, 256. That is the same list as the binary place values, which is why 8 bits give 256 patterns and the largest number is 255.
How do you find the bits needed for a set of items?
- Count the items you must tell apart.
- Find the smallest n where 2n is greater than or equal to that count.
- State n and show the check: 2n is enough, and 2n−1 is not.
Worked example
A weather sensor reports one of 12 different weather codes, such as sunny, cloudy and rain. How many bits does each code need at least?
23 = 8, which is less than 12, so 3 bits are not enough.
24 = 16, which is at least 12, so 4 bits are enough.
The answer is 4 bits. Four of the 16 patterns stay unused, and that is fine.
Now a colour example. An image uses a colour depth of 8 bits per pixel. Colours available: 28 = 256.
If the colour depth is raised to 24 bits, the number of colours is 224 = 16 777 216. The bigger depth gives much richer colour, but each pixel now needs 24 bits instead of 8, so the file is three times larger for the same number of pixels (24 ÷ 8 = 3).
You can check powers of 2 quickly in the Python reasoning sandbox: print(2**8) gives 256 and print(2**24) gives 16777216.
The mistake to watch for
A common slip is multiplying the number of bits by 2 instead of using a power of 2.
Question: How many different values can 4 bits represent?
Mistaken answer: 4 × 2 = 8.
The number of bits is not multiplied by 2. Each extra bit doubles the count, so the right working is 2 × 2 × 2 × 2 = 16.
A second version of the slip is giving 256 as the largest 8-bit number. There are 256 patterns, but they start at 0, so the largest is 255. Ask yourself “how many patterns?” and “what is the largest number?” as separate questions.
Check yourself
1. How many different values can 6 bits represent?
Show answer
26 = 2 × 2 × 2 × 2 × 2 × 2 = 64. Check: 32 doubled is 64.
2. A library codes 40 book categories in binary. What is the smallest number of bits per code?
Show answer
25 = 32 is less than 40, so 5 bits are too few. 26 = 64 is at least 40. The answer is 6 bits.
3. An image has 16 colours. What colour depth does it need, and what happens to the number of colours if one more bit is added?
Show answer
16 = 24, so the depth is 4 bits. Adding one bit makes it 5 bits, and the number of colours doubles to 32.
Where this leads next
Bit depth returns when you study how images and sound are stored, in the Computer Science learning guide. Test everything in this module with the mixed practice set.
If you know the rule but lose marks on the wording of the explanation, a teacher can sharpen that in online one-to-one Computer Science tuition.