Algebra

Completing the Square

Turn ax² + bx + c into a(x − h)² + k — the algebraic move that derives everything

Completing the square turns any quadratic ax² + bx + c into the form a(x − h)² + k by adding and subtracting the right constant. It's the move that derives the quadratic formula, finds parabola vertices, integrates rational functions, and even shows up in physics calculations of minimum-energy configurations. The technique is more useful than the result it produces.

  • GoalRewrite ax² + bx + c as a(x − h)² + k
  • h (vertex x-coordinate)−b / (2a)
  • k (vertex y-coordinate)c − b²/(4a)
  • Constant added(b/(2a))² — the perfect square completion
  • Used to deriveQuadratic formula, vertex of parabola, integration of rational functions
  • Geometric meaningLiterally completing a geometric square (Babylonian origin)

Interactive visualization

Press play, or step through manually. The visualization is yours to drive — try it before reading on.

Open visualization fullscreen ↗

Watch the 60-second explainer

A condensed visual walkthrough — narrated, captioned, under a minute.

The technique step by step

Take any quadratic — let's say x² + 6x + 5. Goal — rewrite as (x − h)² + k.

  1. Look at the coefficient of x — that's 6. Half of it is 3.
  2. Square that — 3² = 9.
  3. Add and subtract 9 — x² + 6x + 9 − 9 + 5.
  4. The first three terms now form a perfect square — (x + 3)² − 9 + 5 = (x + 3)² − 4.

That's it. The vertex form is (x + 3)² − 4. The parabola has vertex at (−3, −4), opens upward, has minimum value −4 at x = −3.

The general formula

For ax² + bx + c with a ≠ 0:

ax² + bx + c = a(x + b/(2a))² + (c − b²/(4a))
             = a(x − h)² + k

where  h = −b/(2a)
       k = c − b²/(4a)

The vertex of the parabola is at (h, k). For a > 0, this is a minimum; for a < 0, a maximum.

Deriving the quadratic formula

Solving ax² + bx + c = 0 by completing the square:

ax² + bx + c = 0
ax² + bx = −c
a(x² + (b/a)x) = −c
a(x² + (b/a)x + (b/(2a))²) = −c + a·(b/(2a))² = −c + b²/(4a)
a(x + b/(2a))² = (b² − 4ac)/(4a)
(x + b/(2a))² = (b² − 4ac)/(4a²)
x + b/(2a) = ±√(b² − 4ac)/(2a)
x = (−b ± √(b² − 4ac))/(2a)

That's the quadratic formula. Completing the square is its proof — there's no simpler derivation.

Worked examples

Example 1 — finding a parabola's vertex

Find the vertex of f(x) = x² − 8x + 12.

x² − 8x + 12
= x² − 8x + 16 − 16 + 12
= (x − 4)² − 4

Vertex is at (4, −4). Minimum value of f is −4, occurring at x = 4. Parabola opens upward.

Example 2 — leading coefficient ≠ 1

Rewrite f(x) = 2x² + 12x + 7 in vertex form.

2x² + 12x + 7
= 2(x² + 6x) + 7
= 2(x² + 6x + 9 − 9) + 7
= 2(x + 3)² − 18 + 7
= 2(x + 3)² − 11

Vertex at (−3, −11). Minimum value −11, occurring at x = −3.

Example 3 — integration via completing the square

Compute ∫ dx / (x² + 4x + 13).

x² + 4x + 13
= x² + 4x + 4 + 9
= (x + 2)² + 9

So the integral is ∫ dx / ((x + 2)² + 9). With u = x + 2 and standard formula ∫ du/(u² + a²) = (1/a) arctan(u/a):

= (1/3) arctan((x + 2)/3) + C

Without completing the square, this integral looks hopeless. With it, one substitution and a standard formula.

Vertex form vs standard form vs factored form

FormEquationRevealsBest for
Standardax² + bx + cy-intercept (c)Polynomial arithmetic, computer storage
Vertexa(x − h)² + kVertex (h, k); axis of symmetry x = hGraphing, optimization, integration of rational functions
Factoreda(x − r₁)(x − r₂)Roots r₁, r₂Solving = 0, sketching x-intercepts

Each form is the same parabola in different clothes; pick whichever surfaces what you care about. Completing the square is the path from standard to vertex form.

JavaScript: completing the square

function completeTheSquare(a, b, c) {
  // Returns { h, k } such that ax² + bx + c = a(x - h)² + k
  if (a === 0) throw new Error('Not a quadratic');
  const h = -b / (2 * a);
  const k = c - (b * b) / (4 * a);
  return { h, k };
}

const { h, k } = completeTheSquare(2, 12, 7);
// h = -3, k = -11
// 2(x - (-3))² + (-11) = 2(x + 3)² - 11

// Find vertex (= minimum if a > 0, max if a < 0)
function vertex(a, b, c) { return completeTheSquare(a, b, c); }
vertex(1, -8, 12);  // { h: 4, k: -4 } — minimum at (4, -4)

Beyond one variable — quadratic forms

The technique extends to multivariable quadratics. For Ax² + Bxy + Cy² + Dx + Ey + F = 0:

  1. Group the second-degree terms — Ax² + Bxy + Cy².
  2. Diagonalize via rotation (eigendecomposition of the matrix [[A, B/2], [B/2, C]]).
  3. In the rotated coordinates, the cross-term vanishes; complete the square in each variable separately.
  4. The result is one of the standard conic forms — ellipse, parabola, hyperbola, or a degenerate case.

This is how you classify a general quadratic curve. The discriminant of the rotation determines the conic type, just as the discriminant of a 1D quadratic determines the root count.

Where completing the square shows up

  • Deriving the quadratic formula. The formula is the result of completing the square on the general quadratic.
  • Finding parabola vertices. Vertex form a(x − h)² + k makes the vertex (h, k) immediately readable. Used in optimization, graphing, projectile-motion analysis.
  • Integrating rational functions. 1/(x² + bx + c) integrates cleanly after completing the square in the denominator.
  • Solving systems of quadratic equations. Particularly conic sections — completing the square in both variables gives the standard form.
  • Physics — energy minimization. Hooke's law, parabolic potentials, harmonic oscillators. The minimum of an energy function is at the vertex of its quadratic approximation.
  • Statistics — least squares. Minimizing the sum of squared errors leads to a quadratic in the parameters; completing the square gives the closed-form least-squares solution.
  • Multivariable Gaussian distributions. The exponent of a multivariate normal is a quadratic form; completing the square in vector form gives the conditional and marginal distributions.

Common mistakes

  • Forgetting to subtract what you added. Adding (b/2)² without subtracting it changes the equation. The technique is "add and subtract (b/2)² inside the same expression."
  • Wrong sign of h. Vertex form is a(x − h)² + k. If the result is (x + 3)², that means h = −3, not +3. The minus sign in the form is what conventional sign-tracking trips on.
  • Not factoring out a first. When a ≠ 1, you must factor it from the x² and bx terms before completing the square inside the parens — otherwise you complete the square wrong.
  • Multiplying outside the parens incorrectly. When you factor a(x² + (b/a)x + (b/(2a))² − (b/(2a))²) + c, the constant inside the parens gets multiplied by a when you distribute. Don't miss the multiplication.
  • Confusing vertex form with factored form. a(x − h)² + k gives the vertex; a(x − r₁)(x − r₂) gives the roots. Different forms; different interpretations.
  • Trying to complete the square when the variable's coefficient is not the standard form. If you have x² + 6x − 1 = 0, you complete the square as x² + 6x + 9 = 1 + 9 = 10, then take square roots. Not as ((x + 3)² = 10).

Frequently asked questions

Why is it called "completing the square"?

Because that's literally what it is. Babylonian mathematicians (~1800 BCE) thought of x² as a square's area and bx as two rectangles attached to it. To make a complete square, you'd need to add a smaller square in the corner — its side is b/2, its area is (b/2)². Adding (b/2)² to x² + bx gives the complete square (x + b/2)². Geometric origin, algebraic technique.

When should I use completing the square instead of the quadratic formula?

Use it when you want vertex form a(x − h)² + k — for graphing parabolas (vertex at (h, k)), finding maxima/minima, or integrating rational functions. Use the quadratic formula when you just want the roots. Both work; pick based on what form you need.

Why does adding (b/(2a))² complete the square?

Because (x + b/(2a))² = x² + (b/a)x + (b/(2a))². The first two terms match the quadratic; the third is the constant we needed to add. So the algebraic identity (x + p)² = x² + 2px + p² with p = b/(2a) gives us exactly the quadratic plus that constant.

What if the leading coefficient isn't 1?

Factor it out first. ax² + bx + c = a(x² + (b/a)x) + c. Now complete the square inside the parens — add and subtract (b/(2a))² inside, accounting for the multiplication by a outside. After algebra — a(x + b/(2a))² + c − b²/(4a). The vertex is at (−b/(2a), c − b²/(4a)).

Where does completing the square show up in calculus?

Integration of rational functions like 1/(x² + bx + c). Completing the square turns the denominator into (x − h)² + k², which has a known antiderivative (1/k · arctan((x − h)/k) when k ≠ 0). Without completing the square, this integral is hard; with it, it's a one-line lookup.

How does completing the square relate to physics?

Energy minimization. Many physics problems give you a quadratic in some variable; completing the square reveals the minimum (or equilibrium point) and how energy varies near it. Hooke's law springs, parabolic potential wells, and the harmonic-oscillator approximation in quantum mechanics all come from completing the square on energy expressions.

Can I complete the square with multiple variables?

Yes — the technique extends to quadratic forms in many variables, like ax² + bxy + cy² + dx + ey + f. Combined with diagonalization, this gives the standard forms of conic sections (ellipse, hyperbola, parabola). It's also how you solve multivariable optimization problems by reducing them to symmetric matrix eigenvalue problems.