# Computing rank and signature of a quadratic form

I don't understand the 'completing the square' method for computing the rank and signature of a quadratic form. The rank and signature are defined to be $p + q$ and $p - q$ respectively, where $p$ and $q$ are the maximum dimensions of positive (resp. negative) definite subspaces of the space the quadratic form is defined on, but I just can't see how this method works.