This question is inspired by this one:
That question was to find all integer solutions to $5x^2 + 5y^2 + z^2 + 4 = 4xy +4yz + 4x$.
The key, as noticed by Andrei Kulunchakov, is that $5x^2 + 5y^2 + z^2 + 4 - 4xy - 4yz - 4x \\ = (4y^2 - 4yz + z^2) + ( 4x^2 - 4xy + y^2) + (x^2 - 4x + 4) \\ = (2y - z)^2 + (2x - y)^2 + (x - 2)^2 $.
My question is a generalization, restricted to quadratics:
Consider the quadratic equation in $n$ variables $f(x_1, ..., x_n) =\sum_{i=1}^n a_i x_i^2 +\sum_{i=1}^n \sum_{j=1}^{i-1} b_{ij}x_ix_j +\sum_{i=1}^n c_i x_i +d = 0 $.
When can $f$ be written in the form $f(x_1, ..., x_n) =\sum_{k=1}^m (\sum_{i=1}^nr_{ki}x_i+s_k)^2 $?
An obvious step is to expand the terms in the latter sum.
$\begin{array}\\ (\sum_{i=1}^nr_{ki}x_i+s_k)^2 &=(\sum_{i=1}^nr_{ki}x_i+s_k)(\sum_{j=1}^nr_{kj}x_j+s_k)\\ &=\sum_{i=1}^n\sum_{j=1}^nr_{ki}r_{kj}x_ix_j +s_k(\sum_{i=1}^nr_{ki}x_i+\sum_{j=1}^nr_{kj}x_j)+s_k^2\\ &=\sum_{i=1}^nr_{ki}^2x_i^2 +2\sum_{i=1}^n\sum_{j=1}^{i-1}r_{ki}r_{kj}x_ix_j +2s_k\sum_{i=1}^nr_{ki}x_i+s_k^2\\ \end{array}\\ $
Summing these up and equating the two representations, we get the system of equations
$\begin{array}\\ a_i &=\sum_{k=1}^m r_{ki}^2\\ b_{ij} &=2\sum_{k=1}^m r_{ki}r_{kj}\\ c_i &=2\sum_{k=1}^m s_kr_{ki}\\ d &=\sum_{k=1}^m s_k^2 \end{array} $
There are possibly $2n+\frac12 n(n-1)+1 =\frac12(n^2-n+4n+2) =\frac12(n^2+3n+2) =\frac12(n+1)(n+2) $ equations in the variables $r_{ki}$ and $s_k$.
The number of variables is $mn+n = n(m+1)$, so we seem to need $\frac12(n+1)(n+2) \ge n(m+1) $ or
$\begin{array}\\ m &\le \dfrac{(n+1)(n+2)}{2n}-1\\ &= \dfrac{n^2+3n+2-2n}{2n}\\ &= \dfrac{n^2+n+2}{2n}\\ &= \dfrac{n+1}{2}+\dfrac1{n}\\ \end{array} $
I'm not sure where to go from here, so I'll leave it at this.