# how to prove $\mathbb Z_n$ has divisors of zero if and only if $n$ is not prime

A non-zero number $a \in \mathbb Z_n$ is called a divisor of zero if there is a non-zero number $b \in \mathbb Z_n$ such that $ab\equiv 0\pmod n.$

How can I prove $\mathbb Z_n$ has divisors of zero if and only if $n$ is not prime.

I filled out the addition and multiplication tables for modulo 6 and 7 and tried to find out the relation, and it's definitely true. I know I need to prove it in both directions since it is an 'iff' question. But I still don't get it.

Notice that for example $3\times 4\equiv 0\pmod {12}$ but none of $3$ or $4$ are zero in mod $12.$
This can not happen with a prime number like $n=13$
If $n$ has non-zero divisors $a,b$ such that $ab=0$ mod $n$, then $ab$ is in the equivalence class of $0$ mod $n$, and so $a,b$ divide $n$, and are both non-zero, and neither are equal to $n$, hence $n$ is not prime. Recall $n = 0$ mod $n$. They also cannot be $1$ since if $a=1$, then $b = n$, and $b$ cannot be zero so...
If $n$ is not prime, then it has divisors $a,b$ with $1<a,b<n$, so that $ab=0$ mod $n$.
If $n$ is not prime, then, we can factorize in the form $ab=n$, then, $ab\equiv n\equiv 0 (\text{mod} \ n)$. The another implication follows from this reasoning (and the definition of a congruence).