The equality x2+7=x2+22+12+12+12 shows that n≤5. It remains to show that x2+7 is not a sum of four (or less) squares of polynomials with rational coefficients. Suppose by way of contradiction that x2+7=f1(x)2+f2(x)2+f3(x)2+f4(x)2, where the coefficients of polynomials f1,f2,f3 and f4 are rational (some of these polynomials may be zero). Clearly, the degrees of f1,f2,f3 and f4 are at most 1. Thus fi(x)=aix+bi for i=1,2,3,4 and some rationals a1,b1,a2,b2,a3,b3,a4,b4. It follows that x2+7=∑i=14(aix+bi)2 and hence
i=1∑4ai2=1,i=1∑4aibi=0,i=1∑4bi2=7
Let pi=ai+bi and qi=ai−bi for i=1,2,3,4. Then
i=1∑4pi2i=1∑4qi2 and i=1∑4piqi=i=1∑4ai2+2i=1∑4aibi+i=1∑4bi2=8=i=1∑4ai2−2i=1∑4aibi+i=1∑4bi2=8=i=1∑4ai2−i=1∑4bi2=−6
which means that there exist a solution in integers x1,y1,x2,y2,x3,y3,x4,y4 and m>0 of the system of equations (i) ∑i=14xi2=8m2, (ii) ∑i=14yi2=8m2, (iii) ∑i=14xiyi=−6m2. We will show that such a solution does not exist. Assume the contrary and consider a solution with minimal m. Note that if an integer x is odd then x2≡1(mod8). Otherwise (i.e., if x is even) we have x2≡0(mod8) or x2≡4 (mod8). Hence, by (i), we get that x1,x2,x3 and x4 are even. Similarly, by (ii), we get that y1,y2,y3 and y4 are even. Thus the LHS of (iii) is divisible by 4 and m is also even. It follows that (2x1,2y1,2x2,2y2,2x3,2y3,2x4,2y4,2m) is a solution of the system of equations (i), (ii) and (iii), which contradicts the minimality of m.