Completing the Square

Algebra

Completing the square is a method of rewriting a quadratic expression into vertex form by adding and subtracting a carefully chosen constant to create a perfect square trinomial.

Formula

x^2 + bx + \left(\frac{b}{2}\right)^2 = \left(x + \frac{b}{2}\right)^2
Visualization

Definition

Completing the square rewrites a quadratic like $x^2 + bx$ as a perfect square trinomial by adding $(b/2)^2$ (and subtracting it back to preserve the value), converting the expression into vertex form. For the general $ax^2 + bx + c$: factor $a$ out of the first two terms if $a \neq 1$, add $(b/2a)^2$ inside (and subtract the equivalent amount outside), then write the result as $a(x + b/(2a))^2 + (c - b^2/(4a))$. This same technique derives the quadratic formula and reduces general conics $ax^2 + bxy + cy^2 + dx + ey + f = 0$ to standard classified form; in linear algebra, completing the square in a quadratic form $Q = x^TAx$ corresponds to diagonalizing $A$ via congruence transformations, a fact formalized as Sylvester's law of inertia.

Example

$x^2 + 6x$: half of $6$ is $3$, and $3^2 = 9$, so $x^2 + 6x = x^2 + 6x + 9 - 9 = (x+3)^2 - 9$. $2x^2 - 12x + 7$: factor out $2$ to get $2(x^2-6x)+7$, add and subtract $9$ inside: $2(x-3)^2 - 18 + 7 = 2(x-3)^2 - 11$, vertex $(3,-11)$. Deriving the quadratic formula: $ax^2+bx+c=0 \implies x^2+\frac{b}{a}x=-\frac{c}{a} \implies \left(x+\frac{b}{2a}\right)^2=\frac{b^2}{4a^2}-\frac{c}{a} \implies x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$.

Key Insight

Think of it as building a square: $x^2 + 6x$ is almost a perfect square, so you add just enough ($9$) to complete it, then subtract that same amount to keep the value unchanged. This is the technique behind the quadratic formula itself and the way to solve quadratics that will not factor over the integers, and every real quadratic form can likewise be diagonalized by completing the square (Sylvester's law of inertia), connecting this elementary trick to spectral theory and the classification of quadratic forms over ordered fields.