Understanding abstract algebra proof of Fermat's Little Theorem The following proof of Fermat's Little Theorem is taken verbatim from Fraleigh's A First Course in Abstract Algebra:

For any field, the nonzero elements form a group under the field multiplication. In particular, for $\mathbb Z_p$, the elements $$1,2,3,\ldots,p-1$$ form a group of order $p-1$ under multiplication modulo $p$. Since the order of any element in a group divides the order of the group, we see that for $b\neq0$ and $b\in\mathbb Z_p$, we have $b^{p-1}=1$ in $\mathbb Z_p$. Using the fact that $\mathbb Z_p$ is isomorphic to the ring of cosets of the form $a+p\mathbb Z$, we see at once that for any $a\in\mathbb Z$ not in the coset $0+p\mathbb Z$, we must have $$a^{p-1}\equiv1\pmod{p}.$$

I have no problem following the proof, except for one thing. The whole proof makes no mention at all about how $p$ must be a prime. Hence it seems like this proof demonstrates Fermat's Little Theorem for all numbers $p$, not just primes, which is absurd! Where precisely does this proof break down when $p$ is not prime? What am I missing? (Sorry if this question is too trivial, but I couldn't find an explanation elsewhere.)

Due to the hint from Bill Dubuque and Doug M, I think I have resolved my own problem. The bolded claim in the proof which is integral to the rest of the proof is only applicable when $\mathbb Z_p$ is indeed a field, which requires that every element in it has a multiplicative inverse, so each of them is coprime with the order of $\mathbb Z_{p}$. In order to have every $1,2,3,\ldots,p-1$ be coprime with $p$ we need $p$ to be prime.
