Solution 1:

There is an expression for this, if $r$ is an integer. See projecteuclid. Also, OEIS A016725.

I am not a number theorist. Just discovered this while searching for something else.

Solution 2:

The problem of the precise number that lies on the surface is of a number theoretic nature. It has to do with the number of ways we can express an integer as the sum of $n$ squares. A lot of modern and classical work in number theory relates to this question.

The other problem, where we count all the points inside instead of just those on the boundary, is of a different flavour. If $a_r$ denotes the number of lattice points on the surface of the 3-d sphere with radius $r$ centered at the origin, then each individual $a_r$ fluctuates quite erratically. If we study the sum $ a_1 + a_2 + \cdots + a_r$ instead, then we get smoother behavior and analytic methods can be applied. For example see here ).