For any number, a, $\displaystyle (x+ a)^2= x^2+ 2ax+ a^2$. Comparing that to $\displaystyle x^2+ bx$ we see that we need 2a= b so that a= b/2 and then $\displaystyle a^2= \frac{b^2}{4}$. To make that a perfect square, we need to add $\displaystyle \frac{b^2}{4}$ and, of course, subtract it:
$\displaystyle x^2+ bx= x^2+ bx+ \frac{b^2}{4}- \frac{b^2}{4}= \left(x- \frac{b}{2}\right)^2- \frac{b^2}{4}$