# Divergence theorem: why are boundaries inside taken in the opposite direction?

I have the following informations $$\underline{F} = \frac{\underline{r}}{r^3}$$ for $\underline{r} \neq 0$ and I also know that $\nabla\cdot\underline{F} = 0$. The surface $S(a)$ is the surface of a sphere of radius $a$ centred at the origin, for which I know $$\iint_S\underline{F}\cdot d\underline{S} = 4\pi$$ Now I consider any surface $\widetilde{S}$ which contains $S$ and I want to evaluate $$\iint_{\widetilde{S}}\underline{F}\cdot d\underline{S}$$ I used the divergence theorem for the volume between $\widetilde{S}$ and $S$ but I only get the correct answer if I take the difference of the surface integrals, instead of the sum, i.e. $$0 = \iiint_{\widetilde{V}}\nabla\cdot\underline{F} = \iint_{\widetilde{S}}\underline{F}\cdot d\underline{S} -\iint_S \underline{F}\cdot d\underline{S}$$

instead of taking $+$ in the last equality. Why does this happen? How do we know that we have to take the difference and not the sum? Furthermore, how do we distinguish between $\widetilde{S}$ being outside and $S$ being inside, or viceversa?

The divergence theorem refers to a solid $B\subset{\mathbb R}^3$ and its two-dimensional boundary $\partial B$. The latter has to be oriented such that the normal points to the outside of $B$ wherever it is defined ($B$ might have edges). The $B$ in your case is maybe a convex body from which a small ball in the interior has been removed. The total boundary of $B$ consists of the outer surface $\tilde S$ of this body, oriented outwards, and the surface $S$ of the small ball, oriented outwards with respect to $B$, which means: towards the origin.