Register plus adder
A counter starts with a register: four flip-flops that each remember one bit. The lamps show the bits with weights 8, 4, 2 and 1. Here 0110 means 4 + 2, so the readout says 6.
The register's bits also flow into an adder that always adds 1. Its answer, 0111, travels back and waits at the register's input. Nothing changes yet: the register only listens at the right moment.
The clock is a signal that turns on and off at a steady rate. Each time it turns on, called a rising edge, the register copies its input. So every tick the number grows by one: 6, 7, 8, 9.
Counting, wrapping, reset
Watch the lamps: the 1s bit flips on every tick, the 2s bit every second tick, the 4s bit every fourth and the 8s bit every eighth. That pattern is just binary counting, 0 up to 15.
At 1111 (15) the adder's answer is 10000, which needs five bits. The register keeps only four, so the extra 1 is lost and it wraps to 0000. Any n-bit counter wraps after 2 to the power n counts.
A reset input forces every flip-flop to 0, whatever the count was. Counting then starts again from zero. Computers press reset like this when they switch on, so they always start from a known state.
Ripple counters
A second kind of counter starts from a toggle flip-flop. It flips its output on every rising clock edge: 0, 1, 0, 1. It changes once per clock tick, so it completes one on-off cycle every two ticks: half the frequency.
Chain four toggle flip-flops so each one is clocked by the one before. Each bit runs at half the speed of the bit before it, and together they count 0 to 15. This is a ripple counter.
Going from 7 to 8, the ripple counter's change travels one stage at a time: 0111, 0110, 0100, 0000, then 1000. The synchronous counter's bits all share one clock, so all four change together.
What counters do
Each stage halves the frequency, so the last of four stages ticks at one sixteenth of the clock. A quartz watch uses the same trick: its crystal vibrates 32,768 times a second, and 15 halvings give exactly one tick per second.
Inside a CPU, a counter called the program counter holds the address of the next instruction to run. After each instruction it adds one and moves on. A jump instruction loads a new address instead of adding one.
Bit by bit
;; step 1/11 · register-holds
;; about: Register, Decimal
bits 8 4 2 1
0 1 1 0
0×8 + 1×4 + 1×2 + 0×1 = 6
Four bits can hold 2^4 = 16 numbers:
0000 (0) up to 1111 (15).
A rising clock edge is the instant the clock signal goes from low (0) to high (1). Flip-flops in a register copy their input only at that instant (Harris and Harris, Digital Design and Computer Architecture, sections 3.2 and 5.4.1). The figure slows the ripple down so you can see it. In a 74HC393 each stage adds a delay of roughly 13 nanoseconds (typical), so a 4-bit ripple is wrong for only a few tens of nanoseconds.