Skip to content
BetterDL

Bit width

Also called: bits needed, number of bits, data width

The number of bits a value or register uses. It fixes how many patterns are available, so it decides which values fit and when overflow happens.

A value's bit width is how many bits it's stored in: a 4-bit value, an 8-bit register, a 32-bit bus. In hardware it's fixed when the circuit is built, and every result has to fit in it.

The width decides:

  • the range: n bits make 2ⁿ patterns
  • the MSB: bit n − 1, which is also the sign bit for signed values
  • when overflow happens: a result outside the range wraps around

How many bits does a value need? Find the smallest n whose range contains it.

  • Unsigned value v: the smallest n with 2ⁿ − 1 ≥ v.
  • Two's complement value v: the smallest n with −2ⁿ⁻¹ ≤ v ≤ 2ⁿ⁻¹ − 1.

Watch exact powers of 2. 256 = 2⁸ needs 9 unsigned bits, because 8 bits stop at 255. And signed ranges are lopsided: −64 fits in 7 bits, but +64 needs 8.

To widen a value, add zeros on the left for unsigned numbers and use sign extension for two's complement.

1
64
1
32
0
16
0
8
1
4
0
2
0
1

Worked examples

Example

Bits needed for 100, unsigned and signed

Compare the value against each width's range.

  1. 1.

    Unsigned: 6 bits reach 63, too small. 7 bits reach 127. So 7 bits: 1100100.

  2. 2.

    Signed +100: 7 bits reach only +63. 8 bits reach +127. So 8 bits.

  3. 3.

    Signed −100: 7 bits reach only −64. 8 bits reach −128. So 8 bits.

Example

A reading from −300 to +300

Two's complement with 9 bits covers −256 to 255, which is too small. 10 bits cover −512 to 511, which contains the whole span. So 10 bits.

Common mistakes

  • Counting decimal digits instead of bits.

  • Forgetting that an exact power of 2 needs one more bit than you might expect.

  • Using the unsigned bit count for a signed value.

Practice Bit width

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Bit width is taught in Number Systems.