I've noticed a type of sum for the number of solutions of a type of quadratic form. For example, the number of solutions to $X^2-Y^2\equiv a\pmod{p}$ for $p$ an odd prime is given by the sum
$$\sum_{Y=1}^p(1+\left(\frac{Y^2+a}{p}\right))$$
where $\left(\frac{Y^2+a}{p}\right)$ is the Legendre symbol. It seems that the trick is to isolate the $X^2$, add 1 to the RHS, and then let $Y$ range over a complete residue system. It seems that for each value $Y$ takes, there will either be 2 or 0 solutions added to the running total. Is there a simple explanation why this is true?
I suspect that for each $y$ that is a solution, we could take both $x$ and $-x$ to get two solutions $(x,y)$ and $(-x,y)$? My only concern is when $x\equiv -x\pmod{p}$, in which case we would have $x\equiv 0\pmod{p}$. Why does the formula still work in that case as well? Thanks for any explanation.