In elementary school, people learn that a prime number is one that isn’t divisible by any number except itself and 1. To translate that into ring theory language, we say it’s not divisible by any element except units and its associates.
But primes can also be defined in another way. If and only if r is prime (or a unit), then r has the property that if it divides ab, it divides a or b. After all, if r = st where s and t are not units, then r divides st but not s or t. On the other hand, if r has no divisors but associates and units, then we can factorize ab and have r somewhere in the factorization, which means that r divides a or b.
Since the last bit requires unique factorization, let’s give these two properties different names: an element that is prime by the elementary school definition is irreducible, while an element that is prime by the new one is prime. The previous paragraph proves that in every ring, every prime is irreducible, and in every ring with unique factorization, every irreducible is prime.
In fact, if every irreducible is prime, then we more or less do have unique factorization. I say more or less because of one pathological annoyance: sometimes we can’t factorize at all. For an example, take Q[x], the ring of all polynomials with rational coefficients; now, take the ring formed by all polynomials in Q[x] whose constant term is an integer. In that ring, we can’t factor x at all, because for example it’s equal to 2(x/2), neither of which is a unit; then x/2 = 2(x/4), and so on.
The condition we impose is called the ascending chain condition on principal ideals. A principal ideal is just an ideal generated by one element, like (2) or (4), but not (2, x) in Z[x]. An ascending chain of ideals is an infinite sequence, I(1), I(2), I(3)… such that I(n) contains I(n-1). The ascending chain condition says that for every ascending chain, there exists an integer m such that I(m) = I(m+1) = I(m+2) = … In the above ring, the condition fails since we have the chain (x), (x/2), (x/4), (x/8)…
In the rings we care about, that is rings created by attaching roots to Z, we always have the ascending chain condition not only on principal ideals but also on ideals in general. So if every irreducible is prime, we have unique factorization. The reason is that by the ACC, we can factor every non-unit into irreducibles, not necessarily uniquely. Now, if a is an element with two different factorizations, p1p2p3…p(m) and q1q2q3…q(n), then since all p‘s and q‘s are irreducible (and hence prime), and p1 divides the product q1q2…q(n), p1 must divide one of the q‘s, say q1.
Now, q1 is irreducible, so p1 must be associate to it; it can’t be a unit, since it’s irreducible. Let’s say that p1 = q1*u, where u is a unit; we can let p‘2 = p2*u and then divide by q1 and get p‘2p3…p(m) = q2q3…q(n). We can repeat the same process as above to see that p‘2 is associate to some q and then divide… this way we can pair the p‘s and q‘s into associates, and get that factorization is in fact unique.