Electric Flux

Consider a uniform electric field in both magnitude and direction passing through a surface of area $$A$$ as in figure 1. Since the total number of electric field lines passing through a surface divided by that surface area (in other words, the line density of the field lines) is proportional to the magnitude of the electric field $$E$$, by multiplying both sides of the proportion by the surface area $$A$$ it is seen that
$$EA∝\text{number of field lines passing through surface}.$$
This product of $$EA$$ is called electric flux:

$$\phi_e=EA.\tag{1}$$

Let us think about what electric flux is by analogy. Suppose that a great rotating blade is submerged underwater and that a flat, square-shaped fishing net of area $$A$$ is placed beside it. The rotating blade will generate a velocity field $$\vec{v}$$ in front of it. Suppose that this velocity field is uniform in both magnitude and direction at all points in space in front of it. Thus the velocity field at every point on the fishing net is constant in both magnitude and direction. Imagine that water particles follow these lines as they pass through the fishing net with constant velocity as indicated by the uniform velocity field $$\vec{v}$$. Imagine that an enormous number of these water particles, right when they reach the surface of the net traveling with velocity $$v=\frac{Δx}{Δt}$$. In a given unit time say $$Δt=1$$ time unit, the water particles will travel a distance $$Δx$$ creating a volume. In a given unit time, the product $$vA$$ measures the volume of water particles that passed through the surface. Letting $$Δt$$ vary, the product $$vA$$ generally refers to the time rate-of-change of the volume of water particles passing through the surface and is called the flux of the velocity field. The flux of the velocity field should be visualized dynamically as water particles passing through the surface filling in a volume $$AΔx$$ every $$Δt$$ seconds. The velocity field lines describe the flow of the water particles through space and the flux of the velocity field through the surface of the fishing net describes the rate of flow of the water particles through that fishing net.
Now suppose that we take the surface and tilt it such that at any point along the surface the angle between the electric field at that point and the normal (to the surface) at that point is $$θ$$. The electric flux through the surface decreases because the number of field lines passing through the surface decreased. It can be seen from the figure that the number of lines passing through the surface whose area is $$A$$ is the same as the number of lines passing through the surface whose area is $$A_⊥$$. Thus the electric flux through both of these surfaces is the same. As we established earlier, Equation (1) indicates the electric flux through a flat surface which is perpendicular to the E-field (where the E-field is constant and uniform at every point along that surface); hence, that previous analysis can be applied to find the electric flux through the perpendicular surface as $$\phi_{e⊥}=EA_⊥=EAcosθ$$. But as just mentioned, the electric flux through the tilted surface is the same as the electric flux through the perpendicular surface. Thus,
$$\phi_e=EA_⊥=EAcosθ.\tag{2}$$
Equation (1) tells us that the electric flux through any flat surface perpendicular to the E-field where the E-field is constant in magnitude and direction over the surface is $$\phi_e=EA$$; Equation (2) tells us that the electric flux through any flat surface tilted at an arbitrary angle $$θ$$ with the E-field where the E-field is constant in magnitude and direction along the surface is $$\phi_e=EAcosθ$$. Notice for Equation (2) that if that angle happens to be $$0°$$, in which case the electric field is perpendicular to the surface, Equation (2) simplifies to being equal to equation (1)—as we’d expect. If $$θ=90°$$, the electric field is parallel to the surface and the electric flux through that surface is zero.  For $$0°<θ<90°$$, the electric flux through the surface varies with (and is proportional to) $$cosθ$$. Thus, according to Equation (2), the electric flux decreases when the surface is slightly tilted—as we’d expect.
We can apply Equation (2) to infinitesimally small surface areas (over which the E-field is nearly constant) to set up an integral which will allow us to find the electric flux through a surface of arbitrary shape where the E-field may vary along that surface. So then consider an arbitrary surface along which the E-field may vary. Imagine that we divide this surface up into an infinite number of infinitesimally small surface elements. Despite the fact that an arbitrary surface can have curvature, if a surface element is infinitesimally small then it is nearly flat. Also, even though the E-field can generally vary in magnitude and direction along the surface, for a very small surface element it is nearly uniform in magnitude and direction. Thus, when we ask the question as to what the electric flux through an infinitesimally small surface element is where the E-field could (as you can imagine) be “coming in” at the surface from any arbitrary direction, we can use Equation (2) to answer this question:
$$d\phi_E=E(dA)cosθ=\vec{E}·d\vec{A}.$$
I would like to point out that the direction of the normal unit vector is arbitrary chosen by convention to be in the “outward direction.” It is chosen to be in the direction which corresponds to an “outflow” of some quantity. Note that the electric flux through any such surface element is $$\vec{E}∙d\vec{A}$$. Thus, to find the total electric flux through the entire surface, one must take the infinite sum of the electric flux through every surface element along the surface:

$$\phi_E≡\int_{surface}\vec{E}·d\vec{A}.\tag{3}$$

Equation (3) tells us the electric flux through any arbitrary surface for any arbitrary E-field; it is thus considered the general definition of electric flux. Since equation (3) holds true for any arbitrary E-field, the quantity $$\vec{E}$$ may be generated from a point-charge, a system of charges, or a continuous charge distribution. The quantity $$\vec{E}$$, if due to the latter two cases, is the electric field due to the entire system or charge distribution.
Very often, we are interested in the electric flux through a closed surface. The direction of the normal unit vector is arbitrarily chosen, by convention, to be “outward” from the closed surface. When the dot product $$\vec{E}·d\vec{A}$$ is positive, it corresponds to an “outflow” of some quantity from the inside of that surface to the outside; if it is negative, it corresponds to an “inflow” of some quantity from the outside to the inside. This quantity could be charge, though generally it does not have to be. Since the net electric flux is proportional to the total number of lines leaving the surface minus the number of lines entering the surface, we know qualitatively that the electric flux is positive whenever more lines are leaving the surface than entering and that it is negative whenever more lines are entering the surface than leaving. This makes sense according to our general definition of flux because in our infinite sum, more positive terms will be added negative (making the net flux positive) and vice versa. The electric flux through a closed surface is
$$\phi_E=∮\vec{E}·d\vec{A}=∮E_ndA.\tag{4}$$