Let $n$ be a positive integer and $0 \leq i < n$. Define
$$
N(i) = \# \left\{ (x\_1,\dots, x\_s) \in [1, n]^s: x\_1^2 +\dots + x\_s^2 \equiv i \mod n \right\}.
$$
I am looking for a reference for the following result: if $s$ is large enough,
$$
n^{s-1} \ll N(i) \ll n^{s-1}
$$
is true for all $i$ and $n$. Could anyone provide a reference for this result? Thank you! Any input also appreciated.



Sum of many squares modulo $n$
The estimate is false for $s\leq 4$, but it is true for $s\geq 5$. For example, if $s=3$ and $8\mid n$ and $i=7$, then $N(i)=0$. Or if $s=4$ and $n=4^k$ and $i=0$, then $N(i)\leq n^2$. For $s\geq 5$ the result follows easily from the fact that the number of ways to write a positive integer $m$ as a sum of $s$ squares is $\asymp\_s m^{s/2-1}$. For more details, see Vaughan's book "The Hardy-Littlewood method".


**Added.** Here are some additional details. From the mentioned bound
$$r\_s(m):=\#\{ x\_1,\ldots,x\_s \in \mathbb{Z}: x\_1^2+\ldots + x\_s^2 = m\} \asymp\_s m^{s/2 - 1},$$
it follows that
\begin{align\*}
N(i)&\leq\sum\_{k=1}^{sn+1} r\_s(kn-n+i)\ll\_s \sum\_{k=1}^{sn+1}(kn)^{s/2-1}\ll\_s n^{s-1},\\
N(i)&\geq\sum\_{k=1}^{n} r\_s(kn-n+i)\gg\_s \sum\_{k=1}^{n}(kn)^{s/2-1}\gg\_s n^{s-1}.
\end{align\*}


