my favorite proof of fermat's little theorem
APR 15, 2026
inkhaven
One of the first things you learn when you learn in elementary number theory is Fermat's Little Theorem (so named to differentiate it from the big bad Last Theorem).
Theorem. (Fermat's Little Theorem) Let be a prime number and be an integer. Then
There are many proofs of this theorem, but my favorite one is a combinatorial proof that goes by counting necklaces. Suppose you have different colored beads. Then the number of length- strings you can make is , since you have choices for each of the beads.
(We'll take and for the images, but the argument holds generally.)
Notice that exactly of these have beads all of the same color, one for each color:
Put those aside and consider the rest of the strings. Batch1 together the strings that form the same necklace (up to rotation) when you join the ends — that is, batch together the strings that differ only by a shift.
Because is prime, shifting any string by spaces gives a different string every time. So each batch has strings in it.2 Then
which is exactly saying that
This is what we wanted! Except that the astute among you have noticed that in original theorem statement, is allowed to be negative.3 But fear not! If is odd, you can just multiply the congruence in by . If , well, it amounts to proving that squaring preserves parity. (Exercise!)
Now we're done.
Like I said, there are other ways to prove this theorem, some of which don't require this goofy "well, actually" at the end. But I like this one in particular because it has such a nice group action flavor.
We can think of the shifting as the group acts on the set of strings of length — an element acts on a string by shifting it by . From a group action perspective, the strings of all one color we were looking at earlier are special. They are the fixed points of the group action, because they are unchanged by any group element acting on them.
The key idea of the necklace proof was comparing the total size of the set of strings with the number of fixed points, modulo . It turns out that what we saw was a special case of a broader fact about group actions, called the fixed point congruence.
Lemma. (Fixed point congruence). Let be a group of order for some prime , and let act on a set . Then
where .
I won't go into the proof here, but the idea is very similar to the "batch things together" approach we used above, just applied more abstractly using the orbit-stabilizer theorem.
This is a pretty powerful lemma, used in the proof of all three Sylow theorems. But for our purposes, we'll just note that is a group of prime power order and then use the lemma to reframe the necklace proof using group actions.
Proof of Fermat's Little Theorem. (By group action). First we note that it is enough to prove the nonnegative case, since if and only if .4
Let be the set of strings of beads, where each bead can be one of colors.5 Observe that . Let act on by translation. Observe that the only fixed points of this action are the strings where the beads are all the same color, so there are fixed points (one for each color). Hence, by the fixed-point congruence, .
It's a little overkill, but I still like it.
footnotes
-
I really want to say "group together," but the word "group" means something else in math land and English has a dearth of words that I could use in its stead. Please bear with the awkward wording ;-; ↩
-
Make sure you believe it! ↩
-
Wait a minute, isn't allowed to be zero, too? Yes, but it's totally legal to follow the proof by having different colors of beads. Or you can observe that the conclusion is trivial if . Whatever floats your boat. ↩
-
This is our "well, actually" from above. ↩
-
Or the set of words of length from an alphabet of letters, if you like. ↩