Difference of Squares
The difference of squares pattern states that $a^2 - b^2$ factors as $(a + b)(a - b)$, applicable whenever a polynomial is a perfect square minus a perfect square.
Formula
a^2 - b^2 = (a + b)(a - b)
Definition
The difference of squares pattern says a perfect square minus a perfect square always factors into two binomials with a plus and a minus: $a^2 - b^2 = (a + b)(a - b)$, for any expressions $a$ and $b$, since the middle terms produced by multiplying them out are opposites and cancel. Both terms must be perfect squares separated by subtraction; a sum of squares $a^2 + b^2$ does not factor this way over the real numbers, though it does over the complex numbers as $(a + bi)(a - bi)$, since $a^2 + b^2$ is irreducible over $\mathbb{R}$ but factors into complex-conjugate factors over $\mathbb{C}$. The identity itself holds in any commutative ring, and whether a "sum of squares" like $x^2 + b^2$ factors in $\mathbb{Z}_p[x]$ depends on whether $-b^2$ is a quadratic residue modulo the prime $p$.
Example
$x^2 - 9 = (x + 3)(x - 3)$ since $9 = 3^2$; checking, $(x+3)(x-3) = x^2 - 3x + 3x - 9 = x^2 - 9$. $25x^2 - 16 = (5x + 4)(5x - 4)$, and $4x^4 - 9y^2 = (2x^2 + 3y)(2x^2 - 3y)$. In $\mathbb{Z}_5$, $x^2 + 1 = x^2 - 4 = (x-2)(x+2)$, since $-1 = 4 \pmod{5}$ and $4 = 2^2$, so the "sum of squares" factors there because $-1$ is a quadratic residue mod $5$.
Key Insight
The middle terms always cancel because $(a+b)(a-b)$ uses the same two terms with just a sign flip, which is why a sum of squares like $x^2 + 16$ resists this kind of factoring over the reals. Whether $-1$ is a quadratic residue modulo a prime $p$ determines whether $x^2 + 1$ factors in $\mathbb{Z}_p[x]$, connecting this elementary pattern to quadratic reciprocity and to which primes split in the Gaussian integers $\mathbb{Z}[i]$.