Continuing on with my explanation, in case you choose to read it or other answers aren't completed,
we were at \(x^2 + 6x\) actually being the first part of our polynomial, the \(a^2 + 2ab\) part. The whole thing was \(a^2 + 2ab + b^2\).
\[\Huge\text{Continuing making it}\\\huge\text{look better with}\\\Huge\text{"Completing the Square"}\]
So, if \(x^2+6x=a^2+2ab\), you can logic out what \(b^2\) is. Let's assume that \(x=a\). Then \(x^2=a^2\) Well, that part's taken care of. Since \(x^2+6x=a^2+2ab\) and \(x^2 = a^2\), guess what we can do next! Subtract that value from both sides. It's okay. If we treat both sides equally, they'll still be equal. \(\cancel{x^2}-\cancel{x^2}+6x=\cancel{a^2} - \cancel{x^2}+2ab\). So, \(6x=2ab\). Hmmm... \(a=x\), right? Then we can divide by that value. Then we see that \(\Large\frac{6\cancel{x}}{\cancel{x}}=\frac{2\cancel{a}b}{\cancel{x}}\). Cleaned up, to see it clearer, we have \(6=2b\). Divide both sides by \(2\), now, so \(b\) is alone. \(\Large\frac{6}{2}=\frac{\cancel{2}b}{\cancel{2}}\normalsize =3=b\). Just like that.
That technique gave us \(x=a\) and \(3=b\). That's for \(a^2+2ab+b^2\).
Here's the thing. We only had \(x^2+6x\) to start with, and the polynomial we want is \(x^2+6x+3^2\). We can't add \(3^2\) out of nowhere... Unless we subtract it at the same time... So, we got from \(x^2 +6x\) to \(x^2+6x+3^2 - 3^2\).
And now, we can complete the square easily. \(a^2 + 2ab + b^2 = (a+b)^2\). Likewise,\[x^2+6x+3^2 -3^2=(x+3)^2-3^2\]Notice how we have to maintain the "\(-3^2\)".