Calculus

Divergence (Vector Calculus)

The flux per unit volume — how much a field is spreading outwards from each point

The divergence of a vector field F = (F_x, F_y, F_z) is the scalar field ∇·F = ∂F_x/∂x + ∂F_y/∂y + ∂F_z/∂z. Geometrically, it is the limit of flux per unit volume — how much the field is spreading outwards (positive: a source) or compressing inwards (negative: a sink) at each point. Divergence is half of the Helmholtz decomposition (curl is the other half), the engine of the divergence theorem (Gauss's theorem), and the bookkeeping that powers continuity equations across physics — fluid mass, electric charge, probability, energy.

  • Definition∇·F = ∂F_x/∂x + ∂F_y/∂y + ∂F_z/∂z
  • Notation∇·F, div F
  • Output typeScalar field
  • Physical meaningFlux per unit volume; source / sink density
  • Divergence theorem∫∫∫ ∇·F dV = ∫∫ F·n̂ dA
  • Used inMaxwell's equations, fluid dynamics, continuity, CFD

Watch the 60-second explainer

A condensed visual walkthrough — narrated, captioned, under a minute.

The Cartesian definition

For a vector field F : ℝ³ → ℝ³ with components F = (F_x, F_y, F_z), the divergence is the scalar field:

∇·F = ∂F_x/∂x + ∂F_y/∂y + ∂F_z/∂z

Each term is a partial derivative of one component with respect to its matching axis. The notation ∇·F suggests a "dot product" between the vector operator ∇ = (∂/∂x, ∂/∂y, ∂/∂z) and the field F — formally a useful mnemonic, even if ∇ is not literally a vector.

The divergence transforms a vector field (F) into a scalar field (∇·F). At each point in space the divergence assigns a single number — positive, negative, or zero.

Flux per unit volume — the geometric definition

The most physically meaningful definition is geometric. Pick a point p. Take any small region V containing p with smooth boundary surface ∂V. Compute the outward flux of F through ∂V:

Φ(V) = ∫∫_{∂V} F · n̂ dA

where n̂ is the outward unit normal to ∂V and dA the area element. As V shrinks toward p:

(∇·F)(p) = lim_{V → p} Φ(V) / Vol(V)

This is the flux per unit volume. It is independent of the shape of V — for any infinitesimally small region around p, the ratio converges to the same number. This coordinate-free definition is more fundamental than the Cartesian formula; the formula is what you get when you specialise to a tiny coordinate cube and take limits.

Sign interpretation:

  • ∇·F > 0 — more flux leaves the point than enters. The point is a source. Field lines emanate from it (think of water bubbling up out of a spring).
  • ∇·F < 0 — more flux enters than leaves. The point is a sink. Field lines converge into it (think of water draining into a drain).
  • ∇·F = 0 — flux in equals flux out. No source or sink. The field is locally conservative in the volume sense (incompressible).

Why ∇·F = ∂F_x/∂x + ∂F_y/∂y + ∂F_z/∂z works

Take a small box centred at p with sides Δx, Δy, Δz. Compute the flux through each pair of opposite faces.

The two faces perpendicular to the x-axis at x ± Δx/2 have outward normals ±x̂. The flux through them is approximately:

F_x(x + Δx/2, y, z) Δy Δz − F_x(x − Δx/2, y, z) Δy Δz
≈ (∂F_x/∂x) Δx Δy Δz

using a first-order Taylor expansion. Similarly the y-faces contribute (∂F_y/∂y) Δx Δy Δz and the z-faces (∂F_z/∂z) Δx Δy Δz. Adding all three pairs:

Φ ≈ (∂F_x/∂x + ∂F_y/∂y + ∂F_z/∂z) · Vol(box)

Dividing by Vol(box) and taking the limit recovers ∇·F = ∂F_x/∂x + ∂F_y/∂y + ∂F_z/∂z. The Cartesian formula is just the flux-per-unit-volume definition specialised to an infinitesimal axis-aligned box.

Worked examples

Radial field F = (x, y, z)

∇·F = ∂x/∂x + ∂y/∂y + ∂z/∂z = 1 + 1 + 1 = 3

Constant divergence everywhere — every point is a uniform source. Field lines emanate from the origin radially, and the volumetric "production rate" is the same everywhere.

Inverse-square field F = r̂ / r² (Coulomb-like)

F = (x, y, z) / (x² + y² + z²)^{3/2}

∂F_x/∂x = ∂/∂x (x · r⁻³) = r⁻³ + x · ∂r⁻³/∂x = r⁻³ − 3x²/r⁵

Adding all three components similarly:
∇·F = 3/r³ − 3(x² + y² + z²)/r⁵ = 3/r³ − 3r²/r⁵ = 0     (away from origin)

Divergence zero everywhere except the origin, where the field blows up. Integrating ∇·F over any region containing the origin yields 4π (a "delta-function source"), which is exactly Gauss's law for a point charge: the field of a unit point charge has divergence concentrated at the charge.

Rigid rotation F = (−y, x, 0)

∇·F = ∂(−y)/∂x + ∂x/∂y + ∂0/∂z = 0 + 0 + 0 = 0

Pure rotation has zero divergence — the field swirls without compressing or expanding. (The curl, by contrast, is non-zero.) Rigid rotation is the canonical example of a divergence-free field.

Divergence vs curl vs gradient

Gradient ∇fDivergence ∇·FCurl ∇×F
Input typeScalar field fVector field FVector field F
Output typeVector fieldScalar fieldVector field
Cartesian formula(∂f/∂x, ∂f/∂y, ∂f/∂z)∂F_x/∂x + ∂F_y/∂y + ∂F_z/∂z(∂F_z/∂y − ∂F_y/∂z, ...)
Physical meaningSteepest-ascent directionSource / sink densityLocal axis & rate of rotation
Vanishes whenf is constantF is incompressible / solenoidalF is conservative / irrotational
Identity∇·(∇×F) = 0 always∇×(∇f) = 0 always
Integral theoremFundamental theorem of line integralsDivergence theorem (Gauss)Stokes' theorem
Maxwell exampleE = −∇φ (electric potential)∇·E = ρ/ε₀ (Gauss's law)∇×E = −∂B/∂t (Faraday)

The Helmholtz decomposition formalises the relationship: any sufficiently smooth, decaying vector field on ℝ³ splits uniquely into a gradient (curl-free) part plus a curl (divergence-free) part. Divergence and curl together capture the complete first-order behaviour of a vector field.

The divergence theorem

The divergence theorem (also known as Gauss's theorem or Ostrogradsky's theorem) connects the local divergence of a field to the global flux through a closed surface:

∫∫∫_V ∇·F dV = ∫∫_{∂V} F · n̂ dA

The volume integral on the left totals the divergence (sources minus sinks) over the region V. The surface integral on the right totals the outward flux through the boundary ∂V. The theorem says these are equal — every unit of volumetric source contributes one unit to the boundary flux, and there is no other way for flux to escape.

This is the engine behind:

  • Gauss's law in electromagnetism. ∫∫ E · n̂ dA = Q_enclosed / ε₀ comes from integrating ∇·E = ρ/ε₀ over the enclosed volume.
  • Conservation laws. Integrating the continuity equation ∂ρ/∂t + ∇·(ρv) = 0 over a region gives d/dt ∫ ρ dV + ∫∫ ρv·n̂ dA = 0 — total mass changes only through boundary flux.
  • Heat-flow analysis. Net heat lost from a region equals the surface flux of −k∇T, which the divergence theorem rewrites as a volume integral of −∇·(k∇T).

The continuity equation — divergence as bookkeeping

Imagine fluid of density ρ(x, t) flowing with velocity v(x, t). The mass flux is ρv (mass per unit area per unit time). Conservation of mass requires that any change in the mass inside a region equals the inflow minus the outflow:

d/dt ∫∫∫_V ρ dV = − ∫∫_{∂V} ρv · n̂ dA

The minus sign because n̂ is outward — outflow is positive flux. By the divergence theorem and bringing the time derivative inside:

∫∫∫_V ∂ρ/∂t dV = − ∫∫∫_V ∇·(ρv) dV

Since this holds for every region V, the integrands must agree pointwise:

∂ρ/∂t + ∇·(ρv) = 0

The continuity equation. The same form governs:

  • Electric charge. ∂ρ_q/∂t + ∇·J = 0 (charge density and current density).
  • Probability in quantum mechanics. ∂|ψ|²/∂t + ∇·j_prob = 0 (Born rule and probability current).
  • Photon number and energy. Photon flux conservation in optics.
  • Particle number in plasmas. Each species satisfies its own continuity equation, coupled through Maxwell's equations.
  • Traffic density. Vehicles on a road obey ∂ρ/∂t + ∇·(ρv) = 0 in 1-D, the basis of macroscopic traffic-flow models (Lighthill–Whitham–Richards, 1955).

The universality is no coincidence — it comes from the divergence theorem applied to any conserved quantity that flows.

Divergence in cylindrical and spherical coordinates

The simple Cartesian sum hides metric factors when you switch coordinates. In cylindrical (r, θ, z) with field F = F_r r̂ + F_θ θ̂ + F_z ẑ:

∇·F = (1/r) ∂(r F_r)/∂r + (1/r) ∂F_θ/∂θ + ∂F_z/∂z

In spherical (ρ, θ, φ) (physics convention, with φ from z) and F = F_ρ ρ̂ + F_φ φ̂ + F_θ θ̂:

∇·F = (1/ρ²) ∂(ρ² F_ρ)/∂ρ
     + (1/(ρ sin φ)) ∂(sin φ · F_φ)/∂φ
     + (1/(ρ sin φ)) ∂F_θ/∂θ

Where do the 1/r and 1/ρ² come from? The geometric definition (flux per unit volume) is coordinate-independent. But the volume element itself differs: r dr dθ dz in cylindrical, ρ²sin(φ) dρ dθ dφ in spherical. To convert flux through curved coordinate cells back to a "per unit volume" rate, you must divide by these Jacobian factors. The metric corrections in the divergence formula are the Jacobian factors recombined with the partial derivatives.

Where divergence appears

  • Electromagnetism. Maxwell's equations include ∇·E = ρ/ε₀ (Gauss's law) and ∇·B = 0 (no magnetic monopoles). Divergence is half the structure of classical electromagnetism.
  • Fluid dynamics. Incompressibility is ∇·v = 0. The Navier–Stokes equations contain ∇·(stress tensor). CFD codes enforce the divergence constraint via pressure-projection methods.
  • Heat and mass transfer. Fourier's law gives heat flux as q = −k∇T; the heat equation comes from −∇·q + heat sources = ρ c_p ∂T/∂t. Diffusion equations everywhere have the same form.
  • Quantum mechanics. The Born-rule probability current j satisfies ∂|ψ|²/∂t + ∇·j = 0. Probability is locally conserved, with j carrying the flow.
  • Computer graphics and CFD. Stable-fluids algorithms project velocity fields onto the divergence-free subspace at each step, enforcing incompressibility.
  • Cosmology and continuum mechanics. Conservation of energy-momentum in general relativity is ∇_μ T^{μν} = 0 — the covariant generalisation of divergence in curved spacetime.
  • Information theory and statistics. The Kullback–Leibler divergence shares a name but is unrelated; the relevant divergence here is the differential operator.

Common mistakes

  • Forgetting metric factors in non-Cartesian coordinates. Computing ∇·F as ∂F_r/∂r + ∂F_θ/∂θ + ∂F_z/∂z is wrong in cylindrical — it misses the (1/r) ∂(r F_r)/∂r form. Powers of r are off, and answers to physics problems come out badly.
  • Treating ∇ as a vector and ∇·F as an actual dot product. The notation is suggestive but not literal. ∇·F obeys product rules unlike a normal dot product (∇·(fF) = f ∇·F + ∇f · F).
  • Confusing divergence with curl. Both involve partial derivatives of a vector field, but divergence sums same-index partials (∂F_x/∂x + …) while curl combines cross-index pairs (∂F_z/∂y − ∂F_y/∂z, …). Different operators with different physical meanings.
  • Concluding ∇·F = 0 means F = 0. Many fields have zero divergence everywhere but are non-zero — e.g., rigid rotation F = (−y, x, 0) and any magnetic field. Zero divergence means no sources, not no field.
  • Forgetting outward-normal convention. The divergence theorem requires n̂ to point outward from V. Using an inward normal flips the sign and gives wrong answers.
  • Mixing scalar and vector fields. Divergence is defined on vector fields. ∇·f for a scalar field f is meaningless; you probably mean ∇f (gradient) or ∇²f (Laplacian, which is ∇·∇f).
  • Computing divergence component-wise in the wrong basis. If you write F in spherical coordinates but treat the components as if they were Cartesian, you will get wrong divergence. The metric factors track which orthogonal basis you are projecting onto.

Frequently asked questions

What does it mean physically that divergence is flux per unit volume?

Imagine a tiny imaginary box around a point. Compute the total flow of F outward through the box's surface (the surface flux). Divide by the box's volume. As the box shrinks to zero, this ratio converges to ∇·F at the point. Positive divergence = more leaves than enters = a source. Negative = more enters than leaves = a sink. Zero = whatever flows in flows out, balanced. The divergence theorem ∫∫∫ ∇·F dV = ∫∫ F·n̂ dA scales this from infinitesimal to finite regions.

What is the continuity equation and why does divergence appear?

The continuity equation ∂ρ/∂t + ∇·(ρ v) = 0 expresses local conservation of any density ρ flowing with velocity v. The first term is the rate of accumulation; the second is the rate of net outflow per unit volume. If more mass is leaving a region than entering, ∇·(ρv) > 0 and ∂ρ/∂t < 0 — density decreases. The same equation governs fluid mass, electric charge (ρ_charge, current density J), probability (Schrödinger), photon number, and traffic density. The form is universal because of the divergence theorem.

What is the difference between divergence, curl, and gradient?

Gradient ∇f takes a scalar field and produces a vector field — the direction of steepest ascent. Divergence ∇·F takes a vector field and produces a scalar field — the local source/sink density. Curl ∇×F takes a vector field and produces a vector field — the local axis of rotation and rate of swirling. They are the three first-order differential operators of vector calculus, and the Helmholtz decomposition states that any sufficiently nice vector field on ℝ³ decomposes uniquely into a curl-free part (a gradient) plus a divergence-free part (a curl).

What is the divergence in cylindrical and spherical coordinates?

Cylindrical: ∇·F = (1/r) ∂(r F_r)/∂r + (1/r) ∂F_θ/∂θ + ∂F_z/∂z. Spherical: ∇·F = (1/ρ²) ∂(ρ² F_ρ)/∂ρ + (1/(ρ sin φ)) ∂(sin φ · F_φ)/∂φ + (1/(ρ sin φ)) ∂F_θ/∂θ. The 1/r and 1/ρ² factors come from the Jacobians of the coordinate transformations. Forgetting them is a classic mistake — students compute ∂F_r/∂r as if it were Cartesian and get answers off by powers of r.

What does Gauss's law have to do with divergence?

Maxwell's first equation, in differential form, is ∇·E = ρ/ε₀ — the divergence of the electric field at a point equals the charge density there divided by the permittivity. Integrate over a volume V using the divergence theorem: ∫∫ E · n̂ dA = (1/ε₀) ∫∫∫ ρ dV = Q_enclosed/ε₀. That is Gauss's law in integral form — the flux through a closed surface equals the enclosed charge over ε₀. Differential and integral forms of Gauss's law are connected directly through the divergence theorem.

What is a divergence-free (or solenoidal) field?

A vector field F with ∇·F = 0 everywhere. Magnetic fields are always divergence-free (∇·B = 0, Maxwell's second equation — there are no magnetic monopoles). Incompressible fluid flow has ∇·v = 0 (mass cannot accumulate anywhere). On simply-connected domains, every divergence-free field is the curl of some vector potential A: F = ∇×A. Divergence-free fields can have flow but no sources or sinks.

How is divergence used in numerical fluid simulation?

Incompressible flow simulations enforce ∇·v = 0 at every step. After computing tentative velocities (which may have non-zero divergence due to forces or boundary effects), a pressure-projection step solves a Poisson equation ∇²p = ∇·v* and corrects v* by subtracting ∇p, restoring incompressibility. This is the core of Chorin's projection method (1968) and modern stable-fluids algorithms (Stam, 1999) used in computer graphics and engineering CFD. Divergence appears explicitly in the algorithm at each time step.