Completing the Square

Learning goals

  • Add the square of half the linear coefficient
  • Rewrite a quadratic in completed-square form
  • Keep both signs when taking a square root of both sides
  • Sort the roots by the sign of the number under the square root
  • Divide by aa first when the leading coefficient is not one

The constant that completes a square

Take x2+6xx^2 + 6x. What constant turns it into a perfect square? The picture below shows the answer. The two terms tile an L-shape for x>0x>0: a square of area x2x^2 and two strips whose areas together make 6x6x. That L is missing one corner, and the corner that fills it is 33 by 33, area 99, because each strip already has length 33. Adding that 99 completes the figure into a full square of side x+3x + 3:

x2+6x+9=(x+3)2.x^2 + 6x + 9 = (x + 3)^2.
Area model for completing the square of x squared plus 6xAn x-by-x square, two 3-by-x strips of area 3x, and a 3-by-3 corner of area 9 together tile a large square of side x plus 3, showing x squared plus 6x plus 9 equals the quantity x plus 3, squared.x3x3x²3x3x9
Completing the square, seen as area. The piece of area x squared and the two strips of area 3x each tile an L-shape. Adding the 3-by-3 corner of area 9 fills the notch, making a full square of side x + 3, so x squared plus 6x plus 9 equals (x + 3) squared.

The picture uses positive side lengths. The algebraic identity also works for negative values of xx or a negative middle coefficient, even though those do not represent lengths in this drawing. You already know from the squares-of-binomials lesson that squaring a sum produces a three-term pattern:

(x+p)2=x2+2px+p2.(x + p)^2 = x^2 + 2px + p^2.

Read this from right to left. Compare x2+6xx^2 + 6x with x2+2px+p2x^2 + 2px + p^2: the middle terms agree when 2p=62p = 6, so p=3p = 3, and the last term must be p2=9p^2 = 9, exactly the corner you just added. The same matching works for any linear coefficient bb in place of 66. Compare x2+bxx^2 + bx with x2+2px+p2x^2 + 2px + p^2: the middle terms agree when 2p=b2p = b, so p=b2p = \tfrac{b}{2}, and the constant that completes the square is p2=(b2)2p^2 = \left(\tfrac{b}{2}\right)^2, the square of half the linear coefficient.

Check by expansion: the middle term of (x+b2)2(x+\tfrac b2)^2 is 2⋅b2⋅x=bx2\cdot\tfrac b2\cdot x=bx, and the last term is (b2)2(\tfrac b2)^2.

So the recipe for the missing constant is short: take the coefficient of xx, halve it, and square the result. For x2+10xx^2 + 10x the half is 55 and the constant is 2525, giving x2+10x+25=(x+5)2x^2 + 10x + 25 = (x + 5)^2. For x2−6xx^2 - 6x the half is −3-3 and the constant is 99, giving x2−6x+9=(x−3)2x^2 - 6x + 9 = (x - 3)^2. The sign inside the binomial follows the sign of bb, because p=b2p = \tfrac{b}{2} carries that sign along.

Check your understanding

What constant must you add to x2+12xx^2 + 12x to complete the square?

Answer choices

Rewriting a quadratic in completed-square form

Worked example 1 Rewrite x2+8x+3x^2 + 8x + 3 in completed-square form

The linear coefficient is b=8b = 8, so half of it is 44 and the constant that completes the square is 42=164^2 = 16. Add and subtract that 1616:

x2+8x+3=(x2+8x+16)−16+3.x^2 + 8x + 3 = \left(x^2 + 8x + 16\right) - 16 + 3.

The parenthesized trinomial is a perfect square, (x+4)2\left(x + 4\right)^2, and the loose constants combine to −16+3=−13-16 + 3 = -13:

x2+8x+3=(x+4)2−13.x^2 + 8x + 3 = (x + 4)^2 - 13.

A quick check expands it back: (x+4)2−13=x2+8x+16−13=x2+8x+3(x + 4)^2 - 13 = x^2 + 8x + 16 - 13 = x^2 + 8x + 3, the original. The constant dropped from 33 to −13-13 precisely because 1616 was borrowed to build the square.

The example adds and subtracts the same number, so the expression keeps its value. In general, x2+bx+cx^2+bx+c needs (b2)2(\tfrac b2)^2 to build the square. Add that number and subtract it again:

x2+bx+c=x2+bx+(b2)2⏟perfect square−(b2)2+c.x^2 + bx + c = \underbrace{x^2 + bx + \left(\frac{b}{2}\right)^2}_{\text{perfect square}} - \left(\frac{b}{2}\right)^2 + c.

The braced terms form (x+b2)2\left(x+\tfrac b2\right)^2. The remaining constants stay outside:

x2+bx+c=(x+b2)2+(c−(b2)2).x^2 + bx + c = \left(x + \frac{b}{2}\right)^2 + \left(c - \left(\frac{b}{2}\right)^2\right).

This is the completed-square form. It says the same thing as the original quadratic, but now xx appears only once, inside the square. Written more generally, every quadratic with leading coefficient 11 can be put in the shape (x−h)2+k(x - h)^2 + k for some constants hh and kk. This is a form we will lean on again later.

Check your understanding

Rewrite x2−10x+18x^2 - 10x + 18 in completed-square form.

Answer choices

Solving a quadratic by completing the square

Worked example 2 Solve x2−6x+4=0x^2 - 6x + 4 = 0

No whole-number factor pair works here. Completing the square gives the roots without that search. Move the constant across:

x2−6x=−4.x^2 - 6x = -4.

Here b=−6b = -6, so b2=−3\tfrac{b}{2} = -3 and (b2)2=9\left(\tfrac{b}{2}\right)^2 = 9. Add 99 to both sides:

x2−6x+9=−4+9=5.x^2 - 6x + 9 = -4 + 9 = 5.

The left side is the perfect square (x−3)2(x - 3)^2, so take the square root of both sides, keeping both signs:

(x−3)2=5⇒x−3=±5.(x - 3)^2 = 5 \quad\Rightarrow\quad x - 3 = \pm\sqrt{5}.

Add 33 to finish:

x=3±5.x = 3 \pm \sqrt{5}.

The two solutions are x=3+5x = 3 + \sqrt{5} and x=3−5x = 3 - \sqrt{5}, both real and irrational, so a search for integer factors could not have found them.

The example uses four steps. For x2+bx+c=0x^2+bx+c=0 with real b,cb,c, the same steps give a general result.

First move the constant to the right side, so the left holds only the xx terms:

x2+bx=−c.x^2 + bx = -c.

Next add (b2)2\left(\tfrac{b}{2}\right)^2 to both sides. Adding it to just the left would change the equation; adding it to both sides keeps the balance while turning the left into a perfect square:

x2+bx+(b2)2=(b2)2−c.x^2 + bx + \left(\frac{b}{2}\right)^2 = \left(\frac{b}{2}\right)^2 - c.

The left side is now (x+b2)2\left(x + \tfrac{b}{2}\right)^2. Take the square root of both sides, and here is the step people forget. A positive number is the square of two different numbers, one positive and one negative, so both must be kept. That is where the ±\pm sign comes from:

x+b2=±(b2)2−c.x + \frac{b}{2} = \pm\sqrt{\left(\frac{b}{2}\right)^2 - c}.

Finally subtract b2\tfrac{b}{2} to isolate xx, which gives the general result

x=−b2±(b2)2−c.x = -\frac{b}{2} \pm \sqrt{\left(\frac{b}{2}\right)^2 - c}.

You do not need to memorize this result: use the four steps with the numbers in your equation. The sign of the number under the square root tells you what kind of answer you get, as the section below shows.

When bb is odd, half of it is a fraction, and (b2)2\left(\tfrac{b}{2}\right)^2 becomes a fraction with 44 in the denominator. The method is the same; you just carry the fractions carefully.

Worked example 3 Solve x2+3x+1=0x^2 + 3x + 1 = 0 (an odd middle coefficient)

Move the constant across, then halve the odd coefficient b=3b = 3:

x2+3x=−1,b2=32,(32)2=94.x^2 + 3x = -1, \qquad \frac{b}{2} = \frac{3}{2}, \qquad \left(\frac{3}{2}\right)^2 = \frac{9}{4}.

Add 94\tfrac{9}{4} to both sides. On the right, write −1-1 as −44-\tfrac{4}{4} so the fractions combine:

x2+3x+94=−1+94=−44+94=54.x^2 + 3x + \frac{9}{4} = -1 + \frac{9}{4} = -\frac{4}{4} + \frac{9}{4} = \frac{5}{4}.

The left side is (x+32)2\left(x + \tfrac{3}{2}\right)^2. Take the square root of both sides, remembering that 54=52\sqrt{\tfrac{5}{4}} = \tfrac{\sqrt{5}}{2} since the denominator 44 is a perfect square:

(x+32)2=54⇒x+32=±52.\left(x + \frac{3}{2}\right)^2 = \frac{5}{4} \quad\Rightarrow\quad x + \frac{3}{2} = \pm\frac{\sqrt{5}}{2}.

Subtract 32\tfrac{3}{2} and combine over the common denominator 22:

x=−32±52=−3±52.x = -\frac{3}{2} \pm \frac{\sqrt{5}}{2} = \frac{-3 \pm \sqrt{5}}{2}.

The single fraction −3±52\dfrac{-3 \pm \sqrt{5}}{2} holds both roots at once, which is the standard way to write them.

Check your understanding

Solve x2+4x+1=0x^2 + 4x + 1 = 0 by completing the square.

Answer choices

Real, repeated, and complex roots

With real coefficients, completing the square gives

(x+b2)2=R,where R=(b2)2−c.\left(x + \frac{b}{2}\right)^2 = R, \qquad \text{where } R = \left(\frac{b}{2}\right)^2 - c.

The sign of RR tells us which kind of square root to use.

If R>0R > 0, its square root is a nonzero real number, so the ±\pm produces two different real solutions, as in x=3±5x = 3 \pm \sqrt{5} above.

If R=0R = 0, its square root is 00, and ±0\pm 0 is just 00, so the two solutions collapse into one repeated solution x=−b2x = -\tfrac{b}{2}. For instance x2−8x+16=0x^2 - 8x + 16 = 0 becomes (x−4)2=0(x - 4)^2 = 0, whose only root is x=4x = 4, met twice.

If R<0R<0, there is no real solution, since a real square cannot be negative. To describe the complex solutions, introduce the imaginary unit ii, a number satisfying i2=−1i^2=-1. The usual rules for multiplying and squaring products still apply, so both 2i2i and −2i-2i square to −4-4:

(2i)2=4i2=−4,(−2i)2=4i2=−4.(2i)^2=4i^2=-4,\qquad (-2i)^2=4i^2=-4.

More generally, for a positive real number kk,

(ik)2=i2k=−k,(−ik)2=−k.(i\sqrt k)^2=i^2k=-k,\qquad (-i\sqrt k)^2=-k.

We write −k=ik\sqrt{-k}=i\sqrt k by convention and keep both signs when solving y2=−ky^2=-k. Thus a negative RR gives x=−b2±i−Rx=-\tfrac b2\pm i\sqrt{-R}. A real number plus a real multiple of ii is a complex number. In −1+2i-1+2i, −1-1 is the real part and 22, the coefficient of ii, is the imaginary part. The two answers form a conjugate pair: their real parts match, and their imaginary parts have opposite signs. These facts are all we need here. The chapter’s first two lessons, Imaginary Numbers and Arithmetic with Complex Numbers (both Advanced), explore them further.

Worked example 4 Solve x2+2x+5=0x^2 + 2x + 5 = 0 (complex roots)

Move the constant across and add (22)2=1\left(\tfrac{2}{2}\right)^2 = 1 to both sides:

x2+2x=−5,x2+2x+1=−5+1=−4.x^2 + 2x = -5, \qquad x^2 + 2x + 1 = -5 + 1 = -4.

The left side is (x+1)2(x + 1)^2, and the right side is negative, which is the signal that the roots are complex:

(x+1)2=−4⇒x+1=±−4.(x + 1)^2 = -4 \quad\Rightarrow\quad x + 1 = \pm\sqrt{-4}.

Use the negative-root convention just stated: −4=i4=2i\sqrt{-4} = i\sqrt{4} = 2i. Then

x+1=±2i⇒x=−1±2i.x + 1 = \pm 2i \quad\Rightarrow\quad x = -1 \pm 2i.

The solutions are x=−1+2ix=-1+2i and x=−1−2ix=-1-2i, a conjugate pair. Both work because x+1=±2ix+1=\pm2i and (±2i)2=−4(\pm2i)^2=-4. We can also check the first in the original equation by expanding:

(−1+2i)2+2(−1+2i)+5=(1−4i+4i2)+(−2+4i)+5=(1−4i−4)−2+4i+5=0.\begin{aligned} &(-1+2i)^2+2(-1+2i)+5 \\ &=(1-4i+4i^2)+(-2+4i)+5 \\ &=(1-4i-4)-2+4i+5=0. \end{aligned}

Allowing complex numbers lets the method finish when R<0R<0. Every quadratic with real coefficients has roots in the complex number system: either two real roots (possibly equal) or a nonreal conjugate pair.

Check your understanding

Solve x2−2x+10=0x^2 - 2x + 10 = 0 by completing the square.

Answer choices

When the leading coefficient is not 1

In a quadratic ax2+bx+c=0ax^2+bx+c=0, a≠0a\ne0, so dividing every term by aa preserves the solutions and leaves the right side equal to 00. When a≠1a\ne1, do this first to make the coefficient of x2x^2 equal to 11, so our pattern applies. Use the new coefficient of xx when deciding what to halve and square.

Worked example 5 Solve 2x2+8x−10=02x^2 + 8x - 10 = 0 and 3x2+6x+9=03x^2 + 6x + 9 = 0

For 2x2+8x−10=02x^2 + 8x - 10 = 0, divide every term by the leading coefficient 22 to make the x2x^2 term stand alone:

2x22+8x2−102=0⇒x2+4x−5=0.\frac{2x^2}{2} + \frac{8x}{2} - \frac{10}{2} = 0 \quad\Rightarrow\quad x^2 + 4x - 5 = 0.

Now complete the square. Move the constant across and add (42)2=4\left(\tfrac{4}{2}\right)^2 = 4 to both sides:

x2+4x+4=5+4=9⇒(x+2)2=9.x^2 + 4x + 4 = 5 + 4 = 9 \quad\Rightarrow\quad (x + 2)^2 = 9.

Take the root of both sides, x+2=±3x + 2 = \pm 3, so x=1x = 1 or x=−5x = -5, two real solutions.

For 3x2+6x+9=03x^2 + 6x + 9 = 0, divide through by 33 first:

x2+2x+3=0.x^2 + 2x + 3 = 0.

Add (22)2=1\left(\tfrac{2}{2}\right)^2 = 1 to both sides after moving the constant over:

x2+2x+1=−3+1=−2⇒(x+1)2=−2.x^2 + 2x + 1 = -3 + 1 = -2 \quad\Rightarrow\quad (x + 1)^2 = -2.

The right side is negative, so the roots are complex. Since −2=i2\sqrt{-2} = i\sqrt{2},

x+1=±i2⇒x=−1±i2.x + 1 = \pm i\sqrt{2} \quad\Rightarrow\quad x = -1 \pm i\sqrt{2}.

Check your understanding

Solve 2x2+4x+10=02x^2 + 4x + 10 = 0 by completing the square.

Answer choices

Running these same steps on the fully general quadratic ax2+bx+c=0ax^2 + bx + c = 0, with letters in place of numbers, produces a single formula for the roots. That is the subject of the next lesson; completing the square is the derivation behind it.

Common mistakes

Practice

Multiple Choice Questions (MCQ)

Progressively harder sets of questions. Each opens on its own page.

Core practice

Practice problems at the level of the course, to be worked out on paper. Hints one at a time, then the answer or the full worked solution, with your progress kept in this browser.

Core practice Work it out on paper 10 problems Start →
More practice (optional)

Extra sets, as hard as the Challenge set. Each one opens on its own page.

More resources (optional)

Other explanations of this lesson, if you want a second take.

A bit of history (optional)

Completing the square was once a geometric instruction. In ninth-century Baghdad, al-Khwarizmi explained equations in words and justified his methods with drawings. One example was what we write as x2+10x=39x^2+10x=39.

His rule halves 1010 to get 55, squares it to get 2525, and adds that to 3939. The new square has area 6464 and side 88, so subtracting 55 gives x=3x=3. A geometric proof surrounds the original square with strips and fills the missing corners. The same added area, 2525, completes the square. Our two-strip drawing uses the same idea with a different arrangement of pieces.

The drawing explains why adding a constant works, but it also limits what counts as an answer: a side length must be positive. Modern algebra gives (x+5)2=64(x+5)^2=64, so x+5=±8x+5=\pm8 and x=3x=3 or x=−13x=-13. The negative answer satisfies the equation, yet cannot be a side in that drawing.

Source: MacTutor’s account of al-Khwarizmi and his geometric proof.

Your progress

See all your progress →