Every state of a counter or finite state machine needs its own bit pattern. n flip-flops give 2ⁿ patterns, so N states need the smallest n with
2ⁿ ≥ N, that is, n = ⌈log₂ N⌉.
The ⌈ ⌉ means round up. Two flip-flops give only 4 patterns, so even 5 states force a third flip-flop.
The safest way avoids logarithms: list powers of 2 (2, 4, 8, 16, 32, 64, 128, 256, …) and stop at the first one that is at least N. Its exponent is the answer. Whatever is left over, 2ⁿ − N, becomes unused states.
That's the minimum, for binary encoding. Other encodings trade flip-flops for simpler logic:
- One-hot and ring counters: N flip-flops for N states.
- Johnson counters: N/2 flip-flops for N states.