Visual walkthrough — Fermat's little theorem (statement)
Before anything else, let us agree on the picture we will draw on the entire page.
We will prove: if you pick a number that does not land on tick (i.e. , read " does not divide "), then lands on tick .
Step 1 — The tick marks we care about
WHAT. Throw away tick . Keep only the non-zero ticks: Here is just a name for this collection of ticks. Nothing more.
WHY. Tick is special: any number that lands there stays stuck there under multiplication (). It cannot participate in the "everything gets 1" magic, so we set it aside. That is exactly the coprimality condition doing its job in advance.
PICTURE. The clock below has . The green ticks are ; the red tick is , quarantined.

Step 2 — Multiplying the whole clock by
WHAT. Pick our number (with ). Take every tick in and multiply it by , then land it back on the clock: Each term says "start at tick , then jump to tick number times , wrapping around."
WHY. We want to compare "the ticks before multiplying" with "the ticks after multiplying." That comparison is the entire engine of the proof, so first we have to see what multiplication by does to the clock.
PICTURE. Below, and . Each green arrow sends tick to tick . Notice the arrows land on — scrambled, but every arrowhead is on a different non-zero tick.

Step 3 — The key claim: no collisions, no zeros
WHAT. The outputs are:
- never tick , and
- all different from one another.
WHY (this is the heart — and where "prime" is essential).
No zeros. Suppose landed on , meaning . Since is prime, if divides a product it must divide one of the factors (Properties of Prime Numbers). But (our choice) and (because is between and ). Contradiction. So no output is .
No collisions. Suppose two inputs collided: . Then , so . Again by primality or . First is false; and is between and , so the only way is . Two "different" inputs were secretly the same. So no genuine collisions.
PICTURE. arrows, each pointing at a distinct non-zero tick. With arrows and exactly non-zero ticks and no repeats, every non-zero tick is hit exactly once. The outputs are the set reshuffled.

Step 4 — Same ticks in, same ticks out ⇒ same product
WHAT. Because the outputs are just shuffled, the product of all outputs equals the product of all inputs:
WHY. Multiplication doesn't care about order: . If two bags hold the same numbers (just poured in a different order), multiplying each bag gives the same total. Step 3 guaranteed the two bags hold exactly the same ticks.
PICTURE. Two bags side by side. Left bag: the original ticks . Right bag: the same ticks, colour-shuffled. A big "" between their products.

Step 5 — Pull the 's out
WHAT. On the left side there are copies of , one from each factor. Collect them:
WHY. The exponent is not chosen by magic — it is simply how many non-zero ticks there are. Every one of the factors on the left carried exactly one ; gathering them turns into the shorthand .
PICTURE. The left product visually "unzipping" into times the tick-product, with each lifted out of its factor.

Let us give the leftover a name: (the "factorial" — just the product of all non-zero ticks). It appears identically on both sides. So:
Step 6 — Cancel the leftover safely
WHAT. Both sides carry the factor . Remove it:
WHY (why cancelling is legal here). You may only cancel a factor modulo if that factor is itself invertible — i.e. coprime to . Is coprime to ? Yes: it is a product of the numbers , and none of them shares a factor with the prime . So it never lands on tick and can be cancelled. (This same "cancelling is safe" fact is why Wilson's Theorem is even able to pin down to .)
PICTURE. The identical factor lifting off both sides of the balance scale, leaving on the left and on the right — and the scale still balanced.

Step 7 — The degenerate case: what if is a multiple of ?
WHAT. Suppose , so lands on tick . Then also lands on , not — the classical form genuinely fails. But the alternative form still holds:
WHY. Two cases exhaust everything:
- If : multiply Step 6 by once more — .
- If : then and , so both sides are tick ; still equal.
Either way . Nothing is left uncovered.
PICTURE. Two mini-clocks: left (, ) shows hitting tick ; right (, ) shows stuck on tick — the alternative form catching the case the classical form drops.

The one-picture summary
The whole derivation on one canvas: multiply the clock by ⇒ ticks reshuffle (prime = no collisions) ⇒ same bag ⇒ same product ⇒ pull out copies of ⇒ cancel the common ⇒ land on .

Recall Feynman retelling (say it in plain words)
I have a clock with a prime number of ticks and I ignore the zero tick. I pick a number that isn't zero on the clock. I multiply every remaining tick by . Because the number of ticks is prime, no two ticks ever crash into each other and none falls onto zero — so I get back exactly the same ticks, just shuffled. Since the same numbers came out (in a new order), multiplying them all gives the same total as before. But every factor on the "after" side smuggled in one copy of , and there were factors, so the after-total is really times the before-total. Same total on both sides means the extra must equal . And if was zero on the clock all along, I just note that and are both zero — so the "" version never fails.
Recall
Why can we cancel modulo a prime ? ::: Because is a product of numbers all coprime to , so it is itself coprime to and therefore invertible — you can divide by it. In Step 3, exactly which fact about primes forbids collisions? ::: If a prime divides a product , it must divide one of the factors; since and , we're forced to . Where does the exponent actually come from? ::: It is the count of non-zero ticks; each of the factors contributes one .
Connections
- Fermat's little theorem (statement) — the parent statement this page derives.
- Modular Arithmetic Basics — the clock and .
- Properties of Prime Numbers — " or ", used in Step 3.
- Multiplicative Group Modulo Prime — the shuffle is bijectivity of .
- Wilson's Theorem — pins down the very we cancelled.
- Euler's Totient Function — replaces by for composite moduli.
- Carmichael Numbers — composites that fake the "no collisions" picture.
- Modular Exponentiation Algorithms — using the result to compute fast.
- RSA Cryptosystem — the payoff application.