Build the idea in three steps
- Divide an integer by a positive integer n and retain its remainder.
- Two integers are congruent modulo n when their difference is divisible by n; for ordinary integers this is the same remainder test.
- ZMod n packages arithmetic modulo n. When n is prime, every nonzero residue can be used as a divisor.
A small example
7 and 2 both leave remainder 2 on division by 5. Their difference 5 is divisible by 5.