• Practice
  • About 13 min
  • 5 practice questions

Bits, bytes and how many values fit

Find how many values n bits can represent and how many bits are needed for a given count of items.

If something looks wrong, please tell us.

A common question type asks how many different values can be stored in a given number of bits, or how many bits are needed to store a given number of items. Both rely on powers of 2.

The key facts

  • With n bits you can make 2^n different patterns.
  • If numbers start from 0, the largest value in n bits is 2^n - 1.
  • To store N different items, find the smallest n such that 2^n is at least N.
Powers of 2
n2^n
12
24
38
416
532
664
7128
8256
101024

Worked examples

Example 1. How many values can 8 bits hold, and what is the largest unsigned number? 2^8 = 256 values, ranging from 0 to 255.

Example 2. How many bits are needed to give a different code to each of 50 items? 2^5 = 32 is too small; 2^6 = 64 is at least 50. So 6 bits.

Example 3. A colour is stored with 3 bits for each of red, green and blue. How many colours? Total bits = 9, so 2^9 = 512 colours.

n bits give 2^n patterns. The largest unsigned value is 2^n - 1.

— Formula to remember

Key takeaways: use 2^n, subtract 1 for the largest value and find the smallest power of 2 that fits.

Check your understanding

  1. 1. How many different values can 6 bits represent?

    1. 6
    2. 12
    3. 32
    4. 64
    Show answer

    Answer: D. n bits give 2^n values: 2^6 = 64.

  2. 2. What is the largest unsigned number that fits in 7 bits?

    1. 127
    2. 128
    3. 64
    4. 255
    Show answer

    Answer: A. The largest unsigned value in n bits is 2^n - 1 = 128 - 1 = 127.

  3. 3. How many bits are needed to give a different code to each of 20 items?

    1. 4
    2. 5
    3. 6
    4. 20
    Show answer

    Answer: B. 2^4 = 16 is too few; 2^5 = 32 is enough, so 5 bits.

  4. 4. A colour uses 2 bits for each of red, green and blue. How many colours are possible?

    1. 6
    2. 12
    3. 64
    4. 8
    Show answer

    Answer: C. Total bits = 3 x 2 = 6, and 2^6 = 64 colours (also 4 x 4 x 4 = 64).

  5. 5. How many different values can 2 bytes hold?

    1. 65,535
    2. 256
    3. 512
    4. 65,536
    Show answer

    Answer: D. 2 bytes = 16 bits, and 2^16 = 65,536. (65,535 is the largest unsigned value, not the count.)

Sign in to keep track of the lessons you finish.

Next lesson → Number systems mixed practice

Privacy · Terms · Refunds · Delivery