If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Completing the square

Some quadratic expressions can be factored as perfect squares. For example, x²+6x+9=(x+3)². However, even if an expression isn't a perfect square, we can turn it into one by adding a constant number. For example, x²+6x+5 isn't a perfect square, but if we add 4 we get (x+3)². This, in essence, is the method of *completing the square*. Created by Sal Khan and CK-12 Foundation.

Want to join the conversation?

  • blobby green style avatar for user Jordan  Salsky
    That wasn't very clear, may you please do another video about that?
    (63 votes)
    Default Khan Academy avatar avatar for user
    • piceratops ultimate style avatar for user Daria
      You don´t need another video because I´m about to explain it to you! Say you have the equation 3x^2-6x+8=23. To complete the square, first, you want to get the constant (c) on one side of the equation, and the variable(s) on the other side. To do this, you will subtract 8 from both sides to get 3x^2-6x=15. Next, you want to get rid of the coefficient before x^2 (a) because it won´t always be a perfect square. Because there is a 3 in front of x^2, you will divide both sides by 3 to get x^2-2x=5. Next, you want to add a value to the variable side so that when you factor that side, you will have a perfect square. In this case, you will add 1 because it perfectly factors out into (x-1)^2. Because you´re taking this value away from the constant, you will add it to the other side of the equation (this might not make sense at first, but if the constant were on the variable side, you would be subtracting). This will all give you the equation (x-1)^2=16. Next, you want to take the square root from both sides so that x-1 is equal to the positive or negative square root of 16 (positive or negative 4). Finally, you add 1 to both sides, taking into account that 4 could be positive OR negative. Therefore, x = -3 or 5. Situations could vary, but this is the basic idea behind the procedure. I hope this helps! :)
      (261 votes)
  • orange juice squid orange style avatar for user Inventive and Unique Username
    Can someone please post the link to the "Last video" of which Sal speaks?
    (20 votes)
    Default Khan Academy avatar avatar for user
  • leaf green style avatar for user Andy Nkansah
    Between to , May i understand why a=-2. i thought it would be 2 instead since were equating -4x to -2ax.
    (14 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user FlyingGlasses
    When would this be more advantageous than using the quadratic formula?
    (9 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user welsh6263
    At , I am confused about where the (x-a)^2 came from and why that is equal to x^2-4x=5
    Could you explain this?
    (4 votes)
    Default Khan Academy avatar avatar for user
    • leaf green style avatar for user TeraVolt
      I hope these following steps help you:
      Now x^2 - 4x = 5
      x^2 - 4x + (something) = 5 + something
      I want to factorise the left side of the equal sign, so I have to find a value for (something) which would allow me to factorise the left-hand side of the equation.
      If (something)=4
      x^2 - 4x + 4 = 5 + 4
      Notice that now I could factorise the left hand side into (x - 2)^2
      (x-2)^2 = 9
      x-2 = root of 9 = + or - 3
      x = +3+2 or -3+2
      x = +5 or -1.
      (x-a)^2 is basically the format of the answer you want receive.
      You want x^2 - 4x + (something) to be equal to (x-a)^2.
      where a is half the coefficient of x(the number before the x), as long a there is no coefficient of x^2. Here a = 2.
      A shorter way to do this is:
      x^2 - 4x = 5
      (x - (4/2))^2 - (4/2)^2 = 5
      (x-2)^2 - 4 = 5 and so on. But remember, you only halve the coefficient of x and put it into the brackets only if there is no number before x^2 (coefficient of x^2). If it is there then you have to divide the whole equation first by the coefficient and then halve the coefficient of x and put it into the brackets.
      Sal uses (x - a)^2 simply to tell this is the format of the factorised form of :
      x^2 -4x +? = (x - a)^2, where a = 2 (4 divided by two).
      Sorry for the large number of words used to answer your question.
      (11 votes)
  • aqualine ultimate style avatar for user Arthur Zou
    honestly even if this is useful in real life I hope I don't encounter a circumstance where I need this math
    (8 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user honickmannoah
    Why did he say that we needed a a number times 2 to equal -3 (it was around )?
    (7 votes)
    Default Khan Academy avatar avatar for user
  • duskpin ultimate style avatar for user P,


    isn't a perfect square trinomial

    (ax-b)^2 = (ax)^2+2abx+b^2?

    I get a bit confused as to why, when using the completing the square to derive the quadratic formula we only divide by 2, whit out also dividing by a.

    but we do, right? we do it at the beginning.

    ax^2+bx+c = 0

    1/a*(ax^2+bx+c) = (0)1/a

    x^2+bx/a + (b/2a)^2 = -x/a - (bx/2a)^2

    In that step, we divide the second term by 2a to isolate b, and raise it to a second power.

    I'm just trying to confirm things, not sure if I’m wrong
    (3 votes)
    Default Khan Academy avatar avatar for user
    • female robot grace style avatar for user loumast17
      Just a quick correction.
      (ax-b)^2 = (ax)^2 - 2abx + b^2
      (ax+b)^2 = (ax)^2 + 2abx + b^2

      And I'm not sure where x^2+bx/a + (b/2a)^2 = -x/a - (bx/2a)^2 came from. Step by step though:

      Start with ax^2 + bx + c = 0
      Factor out a

      a(x^2 + (b/a)x + c/a) = 0
      Now we complete the square using the term (b/a)/2 or b/(2a), adding and subtracting it to the one side so we don't change the value. Or we could add it to both sides, but then you would have to take into account the factored out a. Let me know if that doesn't make sense.

      a(x^2 + (b/a)x + (b/(2a))^2 - (b/(2a))^2 + c/a)
      x^2 + (b/a)x + (b/(2a))^2 = (x + b/(2a))^2 by being a perfect square trinomial [a = 1, b = b/(2a),hope that's not too confusing.]

      a((x + b/2a)^2 - (b/(2a))^2 + c/a) = 0
      And this will get you into vertex form.

      From here you can derive the quadratic formula by solving for x. If you'd like me to walk through that let me know.
      (3 votes)
  • female robot grace style avatar for user Points
    Around , Sal divides the quadratic equation by 5. This process makes the coefficient of x^2 equal to 1. My question is does the coefficient of x^2 need to be 1 to complete the square.
    (5 votes)
    Default Khan Academy avatar avatar for user
    • piceratops tree style avatar for user Saehui Hwang
      no it doesn't have to.

      for example; 2x^2+18x+16
      one can factor this by..
      (x+8)(2x+2)

      but if you divide everthing by 2,
      you can make 2x^2+18x+16 to x^2+9x+8 then you can factor this to
      (x+8)(x+1)

      you see, this is the same as (x+8)(2x+1) but simpler.

      so to answer your question; it doesn't matter, but is's the matter of which one is simpler

      hope this helps :)
      (2 votes)
  • piceratops ultimate style avatar for user Aseem Deuskar
    He is missing a lot of steps in his work.
    (4 votes)
    Default Khan Academy avatar avatar for user

Video transcript

In this video, I'm going to show you a technique called completing the square. And what's neat about this is that this will work for any quadratic equation, and it's actually the basis for the quadratic formula. And in the next video or the video after that I'll prove the quadratic formula using completing the square. But before we do that, we need to understand even what it's all about. And it really just builds off of what we did in the last video, where we solved quadratics using perfect squares. So let's say I have the quadratic equation x squared minus 4x is equal to 5. And I put this big space here for a reason. In the last video, we saw that these can be pretty straightforward to solve if the left-hand side is a perfect square. You see, completing the square is all about making the quadratic equation into a perfect square, engineering it, adding and subtracting from both sides so it becomes a perfect square. So how can we do that? Well, in order for this left-hand side to be a perfect square, there has to be some number here. There has to be some number here that if I have my number squared I get that number, and then if I have two times my number I get negative 4. Remember that, and I think it'll become clear with a few examples. I want x squared minus 4x plus something to be equal to x minus a squared. We don't know what a is just yet, but we know a couple of things. When I square things-- so this is going to be x squared minus 2a plus a squared. So if you look at this pattern right here, that has to be-- sorry, x squared minus 2ax-- this right here has to be 2ax. And this right here would have to be a squared. So this number, a is going to be half of negative 4, a has to be negative 2, right? Because 2 times a is going to be negative 4. a is negative 2, and if a is negative 2, what is a squared? Well, then a squared is going to be positive 4. And this might look all complicated to you right now, but I'm showing you the rationale. You literally just look at this coefficient right here, and you say, OK, well what's half of that coefficient? Well, half of that coefficient is negative 2. So we could say a is equal to negative 2-- same idea there-- and then you square it. You square a, you get positive 4. So we add positive 4 here. Add a 4. Now, from the very first equation we ever did, you should know that you can never do something to just one side of the equation. You can't add 4 to just one side of the equation. If x squared minus 4x was equal to 5, then when I add 4 it's not going to be equal to 5 anymore. It's going to be equal to 5 plus 4. We added 4 on the left-hand side because we wanted this to be a perfect square. But if you add something to the left-hand side, you've got to add it to the right-hand side. And now, we've gotten ourselves to a problem that's just like the problems we did in the last video. What is this left-hand side? Let me rewrite the whole thing. We have x squared minus 4x plus 4 is equal to 9 now. All we did is add 4 to both sides of the equation. But we added 4 on purpose so that this left-hand side becomes a perfect square. Now what is this? What number when I multiply it by itself is equal to 4 and when I add it to itself I'm equal to negative 2? Well, we already answered that question. It's negative 2. So we get x minus 2 times x minus 2 is equal to 9. Or we could have skipped this step and written x minus 2 squared is equal to 9. And then you take the square root of both sides, you get x minus 2 is equal to plus or minus 3. Add 2 to both sides, you get x is equal to 2 plus or minus 3. That tells us that x could be equal to 2 plus 3, which is 5. Or x could be equal to 2 minus 3, which is negative 1. And we are done. Now I want to be very clear. You could have done this without completing the square. We could've started off with x squared minus 4x is equal to 5. We could have subtracted 5 from both sides and gotten x squared minus 4x minus 5 is equal to 0. And you could say, hey, if I have a negative 5 times a positive 1, then their product is negative 5 and their sum is negative 4. So I could say this is x minus 5 times x plus 1 is equal to 0. And then we would say that x is equal to 5 or x is equal to negative 1. And in this case, this actually probably would have been a faster way to do the problem. But the neat thing about the completing the square is it will always work. It'll always work no matter what the coefficients are or no matter how crazy the problem is. And let me prove it to you. Let's do one that traditionally would have been a pretty painful problem if we just tried to do it by factoring, especially if we did it using grouping or something like that. Let's say we had 10x squared minus 30x minus 8 is equal to 0. Now, right from the get-go, you could say, hey look, we could maybe divide both sides by 2. That does simplify a little bit. Let's divide both sides by 2. So if you divide everything by 2, what do you get? We get 5x squared minus 15x minus 4 is equal to 0. But once again, now we have this crazy 5 in front of this coefficent and we would have to solve it by grouping which is a reasonably painful process. But we can now go straight to completing the square, and to do that I'm now going to divide by 5 to get a 1 leading coefficient here. And you're going to see why this is different than what we've traditionally done. So if I divide this whole thing by 5, I could have just divided by 10 from the get-go but I wanted to go to this the step first just to show you that this really didn't give us much. Let's divide everything by 5. So if you divide everything by 5, you get x squared minus 3x minus 4/5 is equal to 0. So, you might say, hey, why did we ever do that factoring by grouping? If we can just always divide by this leading coefficient, we can get rid of that. We can always turn this into a 1 or a negative 1 if we divide by the right number. But notice, by doing that we got this crazy 4/5 here. So this is super hard to do just using factoring. You'd have to say, what two numbers when I take the product is equal to negative 4/5? It's a fraction and when I take their sum, is equal to negative 3? This is a hard problem with factoring. This is hard using factoring. So, the best thing to do is to use completing the square. So let's think a little bit about how we can turn this into a perfect square. What I like to do-- and you'll see this done some ways and I'll show you both ways because you'll see teachers do it both ways-- I like to get the 4/5 on the other side. So let's add 4/5 to both sides of this equation. You don't have to do it this way, but I like to get the 4/5 out of the way. And then what do we get if we add 4/5 to both sides of this equation? The left-hand hand side of the equation just becomes x squared minus 3x, no 4/5 there. I'm going to leave a little bit of space. And that's going to be equal to 4/5. Now, just like the last problem, we want to turn this left-hand side into the perfect square of a binomial. How do we do that? Well, we say, well, what number times 2 is equal to negative 3? So some number times 2 is negative 3. Or we essentially just take negative 3 and divide it by 2, which is negative 3/2. And then we square negative 3/2. So in the example, we'll say a is negative 3/2. And if we square negative 3/2, what do we get? We get positive 9/4. I just took half of this coefficient, squared it, got positive 9/4. The whole purpose of doing that is to turn this left-hand side into a perfect square. Now, anything you do to one side of the equation, you've got to do to the other side. So we added a 9/4 here, let's add a 9/4 over there. And what does our equation become? We get x squared minus 3x plus 9/4 is equal to-- let's see if we can get a common denominator. So, 4/5 is the same thing as 16/20. Just multiply the numerator and denominator by 4. Plus over 20. 9/4 is the same thing if you multiply the numerator by 5 as 45/20. And so what is 16 plus 45? You see, this is kind of getting kind of hairy, but that's the fun, I guess, of completing the square sometimes. 16 plus 45. See that's 55, 61. So this is equal to 61/20. So let me just rewrite it. x squared minus 3x plus 9/4 is equal to 61/20. Crazy number. Now this, at least on the left hand side, is a perfect square. This is the same thing as x minus 3/2 squared. And it was by design. Negative 3/2 times negative 3/2 is positive 9/4. Negative 3/2 plus negative 3/2 is equal to negative 3. So this squared is equal to 61/20. We can take the square root of both sides and we get x minus 3/2 is equal to the positive or the negative square root of 61/20. And now, we can add 3/2 to both sides of this equation and you get x is equal to positive 3/2 plus or minus the square root of 61/20. And this is a crazy number and it's hopefully obvious you would not have been able to-- at least I would not have been able to-- get to this number just by factoring. And if you want their actual values, you can get your calculator out. And then let me clear all of this. And 3/2-- let's do the plus version first. So we want to do 3 divided by 2 plus the second square root. We want to pick that little yellow square root. So the square root of 61 divided by 20, which is 3.24. This crazy 3.2464, I'll just write 3.246. So this is approximately equal to 3.246, and that was just the positive version. Let's do the subtraction version. So we can actually put our entry-- if you do second and then entry, that we want that little yellow entry, that's why I pressed the second button. So I press enter, it puts in what we just put, we can just change the positive or the addition to a subtraction and you get negative 0.246. So you get negative 0.246. And you can actually verify that these satisfy our original equation. Our original equation was up here. Let me just verify for one of them. So the second answer on your graphing calculator is the last answer you use. So if you use a variable answer, that's this number right here. So if I have my answer squared-- I'm using answer represents negative 0.24. Answer squared minus 3 times answer minus 4/5-- 4 divided by 5-- it equals--. And this just a little bit of explanation. This doesn't store the entire number, it goes up to some level of precision. It stores some number of digits. So when it calculated it using this stored number right here, it got 1 times 10 to the negative 14. So that is 0.0000. So that's 13 zeroes and then a 1. A decimal, then 13 zeroes and a 1. So this is pretty much 0. Or actually, if you got the exact answer right here, if you went through an infinite level of precision here, or maybe if you kept it in this radical form, you would get that it is indeed equal to 0. So hopefully you found that helpful, this whole notion of completing the square. Now we're going to extend it to the actual quadratic formula that we can use, we can essentially just plug things into to solve any quadratic equation.