I have been reading a bit about vector fields and how it relates to the EM field. However, I am confused about the nature of Gauss's law. As far as I understand, it is supposed to relate flux of the lines over a surface to the net charge inside the closed surface. But how is that relationship achieved? Gauss's divergence law allows one to find the divergence through a closed surface, but how is that connected to the charge of the surface?
[Physics] How is Gauss’s divergence theorem related to Gauss’s law
electric-fieldselectrostaticsgauss-lawVector Fields
Related Solutions
In an attempt to be brief: The big thing to remember is that the flux is also proportional to the area (technically, the surface integral of the field over the area). Crudely speaking, the side of the enclosed surface with exiting field lines are further away from the external charge than the side with "entering" field lines, and the surface area increases by $r^2$ (remember the formula for the surface area of a sphere). Gauss's Law is just a mathematically precise way of stating this compensation.
(Image source: http://www.ux1.eiu.edu/~cfadd/1360/24Gauss/Gauss.html)
First, just to be clear, the flux through the base is NOT zero. If it helps to think about it this way, imagine lines of flux escaping uniformly and radially from the point charge and going to infinity. The number of flux lines that will hit the base of the cone depends on the solid angle subtended by the cone - the further away you move the base, the more slanted the sides of the cone get and the fewer lines remain within the cone and hit the base. More precisely, if the solid angle subtended by the cone is $\Omega$, the flux through the base is given by $(\Omega/4\pi)\times(q/\epsilon_0)$. As the base gets further, the solid angle $\Omega \to 0$ and hence the flux $\to 0$. You could check this by starting with the Coulomb formula for the electric field due to a point charge and computing the surface integral of the flux of the through the base (let me know if you aren't sure how one would go about doing this; I will edit to show how). However, the computation is not very illuminating; while I usually don't like thinking in terms of flux lines, for the very simple charge distribution of a single point charge that we have, it makes the physics very clear. Also, I would be careful with making statements like "As the charge moves far away, its "influence" on the fixed base almost vanishes; how can the flux remain constant?". The decrease in the flux doesn't come just from the weakening of the field; the important thing is the fraction of the the flux.
Now, how do we reconcile this with Gauss' law? Well, the answer is that it is generally not a good idea to take surface integrals with discontinuous charge distributions (e.g. point or surface charge distributions) lying on the surface of integration. One way to resolve the issue is similar to what Cicero suggests in his answer - think of the point charge as a small sphere; the fraction of charge lying in the cone is exactly the solid angle subtended by the sides of the cone, i.e., $\Omega/4\pi$, and hence Gauss' law is gives you the same result, even as you take the limit where the radius of the small sphere $\to 0$. The other way to resolve this is to deform the tip of the cone slightly from a point so that the charge is unambiguously inside or outside. If you "flatten" the tip, then the charge contained in the deformed "cone" is 0, but the total flux through its surface is also 0 - the newly introduced top surface contributes $-(\Omega/4\pi)\times(q/\epsilon_0)$, the sides contribute nothing and the base contributes $(\Omega/4\pi)\times(q/\epsilon_0)$. If instead you "stretch" the tip so it contains the point charge, then the charge contained in the deformed "cone" is $q$, but the total flux through its surface is $q/\epsilon_0$ in accordance with Gauss' law - however you end up deforming the tip, the newly introduced top surface contributes $(1-\Omega/4\pi)\times(q/\epsilon_0)$, the sides contribute nothing and the base contributes $(\Omega/4\pi)\times(q/\epsilon_0)$. So, your P.S. is semi-true - Gauss' law, in its differential form is not the problem, but one must be careful when taking surface integrals near discontinuities in a charge distribution.
Best Answer
Mathematical Explanation
Gauss's divergence law states that
$$\mathbf{\nabla} \cdot \mathbf{E} = \frac{\rho}{\epsilon_0} $$
So, let's integrate this on a closed volume $V$ whose surface is $S$, it becomes
$$ \iiint\limits_{V(S)}\nabla \cdot \mathbf{E}\,\textrm{d}V = \frac{Q}{\epsilon_0} $$
where $Q$ is the total charge in $V$. However, Green-Ostrogradski theorem states that
$$ \iiint\limits_{V(S)} \nabla \cdot \mathbf{F}\,\textrm{d}V = \iint\limits_{S}\mathbf{F}\cdot\mathbf{\textrm{d}S}$$
for any field $\mathbf{F}$, so in particular
$$ \iiint\limits_{V(S)} \nabla\cdot\mathbf{E}\,\textrm{d}V = \iint\limits_{S}\mathbf{E}\cdot\mathbf{\textrm{d}S} = \Phi_S(\mathbf{E})$$
where $\Phi_S(\mathbf{E})$ is the flux of $\mathbf{E}$ through $S$. Finally, we got
$$ \Phi_S(\mathbf{E}) = \frac{Q}{\epsilon_0}$$
which is Gauss's theorem.
Intuitive Explanation
The previous explanation demonstrates the link between Gauss's divergence law and its theorem, yet we don't really understand why it works. However, once you've understood what the divergence of a field is, it will appear easy to understand.
Let's start from a possible definition of the divergence of a field $\mathbf{F}$:
$$ \nabla \cdot \mathbf{F} = \lim\limits_{\delta\tau\rightarrow 0} \frac{\iint\limits_{\delta S}\mathbf{F}\cdot\mathbf{\mathrm{d}S}}{\delta \tau}$$
where $\delta \tau$ is the volume delimited by $\delta S$. Well... this definition isn't really simple. Let's rewrite it as a physicist would do:
$$\nabla \cdot \mathbf{F}\, \delta \tau = \Phi_{\delta S}(\mathbf{F})$$
where $\delta \tau$ is small enough.... So here, we can see that the divergence of $\mathbf{F}$ is how much of $\mathbf{F}$ goes out of a small volume per unit time. So, if we integrate this over a big volume, we will get what comes out of this big volume per unit time (since when we cut this big volume into many small volumes, everything that goes out of a small volume goes in one of its neighbours, except for the extreme small volumes). But what goes out of this big volume is $\Phi_S(\mathbf{F})$, so we can say that
$$ \Phi_S(\mathbf{F}) = \sum\limits_{\delta \tau \in V} \Phi_{\delta S}(\mathbf{F}) = \sum\limits_{\delta\tau \in V} \nabla\cdot\mathbf{F}\,\delta \tau = \iiint\limits_{V}\nabla\cdot\mathbf{F}\,\mathbf{\textrm{d}V}$$
To a possible understanding of Gauss's law
Everyone starts electrostatic with Coulomb's law, that is two charges $q_A$ and $q_B$ with a distance $r$ between them undergo a force
$$ F_e = \frac{q_A q_B}{4\pi \epsilon_0 r^2}$$
Now, let's consider a charge $q$ in $O$. It creates a field $$\mathbf{E} = \frac{q}{4\pi\epsilon_0 \| \mathbf{OM} \|^3} \mathbf{OM}$$
Consider a small surface $\textrm{d}^2 S = r^2\textrm{d}\theta\textrm{d}\phi$ in $M$, where $\|OM\| = r$. The flux of $\mathbf{E}$ through $\textrm{d}^2 S$ is $\textrm{d}^2\Phi = \mathbf{E}\cdot\textrm{d}^2\mathbf{S}$ where $\textrm{d}^2\mathbf{S} = \frac{\textrm{d}^2S}{r}\mathbf{OM}$. This finally gives
$$ \textrm{d}^2\Phi = \frac{q}{4\pi\epsilon_0 r^3}\mathbf{OM}\cdot\frac{r^2\textrm{d}\theta\textrm{d}\phi}{r}\mathbf{OM} = \frac{q}{4\pi\epsilon_0}\textrm{d}\theta\textrm{d}\phi$$
Now, let's consider a closed surface $S$. If $O$ is in this surface, then
$$ \Phi = \iint\limits_S \frac{q}{4\pi\epsilon_0}\textrm{d}\theta\textrm{d}\phi = \frac{q}{4\pi\epsilon_0} \int\limits_{\theta = 0}^{2\pi}\int\limits_{\phi = 0}^{\pi} \textrm{d}\theta\textrm{d}\phi = \frac{q}{\epsilon_0}$$
Now, focus on the case were $O$ is outside $S$. Let $S_{+}$ (resp. $S_{-}$) be the part of $S$ where $\textrm{d}^2\Phi \geq 0$ (resp. $\textrm{d}^2\Phi < 0$), then
$$ \iint\limits_{S} \textrm{d}^2\Phi = \frac{q}{4\pi\epsilon_0}(\iint\limits_{S_{+}}\textrm{d}\theta\textrm{d}\phi - \iint\limits_{S_{-}}\textrm{d}\theta\textrm{d}\phi) $$
However, since $S$ is a closed surface, a drawing can convince you that the preceding sum is null (the solid angle of $S_{-}$ is the same as the one of $S_{+}$...). Then, when $O$ is outside of $S$, $\Phi$ = 0.
Since the electrostatic field is linear, we can generalize this idea with the following equation:
$$ \Phi_S(\mathbf{E}) = \frac{Q}{\epsilon_0} $$
where $Q$ is the net charge inside $S$.