Does there exist asymptotic formula for ways to write n as sum of four squares? Or can this be proved impossible? I can only find reference for sums of five squares.
The function you are asking for is $r_4(n)$, the number of ways to write $n$ as a sum of four squares. The exact formula was discovered by Jacobi, and is given as
$$\displaystyle r_4(n) = 8\sum_{\substack{d  n \\ 4 \nmid d}} d.$$
Note that $$L(x) = \sum_{n\leq x} r_4(n)$$ is the number of lattice points in the ball of radius $\sqrt{x}.$
It is known that $$L(x) = \frac{\pi^2}2 x^2 + O(x \log(x)).$$ (the error term can be improved slightly, but this is not important here). This means that that $r_4(n)$ (which is the number of lattice points on the sphere of radius $\sqrt{n})$ is bounded by $O( n \log n).$ An asymptotic formula does not exist, since for $n$ prime, Jacobi's formula gives $8(n+1),$ while Gronwall's theorem tells us that this is as big as $c n \log \log n$ infinitely often.
A nice reference (but far from the only one) is:
Ivi\'c, A.; Kr\"atzel, E.; K\"uhleitner, M.; Nowak, W.G., Lattice points in large regions and related arithmetic functions: recent developments in a very classic topic, Schwarz, Wolfgang (ed.) et al., Elementare und analytische Zahlentheorie. Tagungsband. Stuttgart: Franz Steiner Verlag (ISBN 3515087575/hbk). Schriften der Wissenschaftlichen Gesellschaft an der JohannWolfgangGoetheUniversit\"at Frankfurt am Main 20, 89128 (2006). ZBL1177.11084.

$\begingroup$ Your asymptotic implies $r_4(n)=L(n)L(n1)=O(n\log n)$ (assuming that $p$, whatever that is, is constant). Where does the $n^{3/2}$ come from? $\endgroup$ – Emil Jeřábek supports Monica Apr 12 '17 at 17:03


Stanley Yao Xiao gave a perfect answer, but let me remark that $r_4(n)$ also equals $n$ times the usual singular series (familiar from the circle method) when $4\nmid n$. The difference with five or more squares is that the singular series does not vary between two positive constants: instead, it varies between $1$ and a constant times $\log\log n$. Note also that $r_4(n)$ is very small when $n$ is divisible by a large power of $2$.
For more details, see HeathBrown: A new form of the circle method, and its application to quadratic forms (J. reine angew. Math. 481 (1996), 149206), especially Theorem 4 and Corollary 1.