---
title: Gauss’s Law for Magnetism
module: Magnetic Sources
moduleNumber: 7
lessonNumber: 5
order: 705
summary: >
  Electric field lines start and end on charges; magnetic field lines do neither,
  because no one has ever found an isolated magnetic pole. That single experimental fact
  is Gauss's law for magnetism: the flux of $\vec B$ through any closed surface is zero,
  $\oint\vec B\cdot\d\vec A=0$, or in differential form $\nabla\cdot\vec B=0$. We work through
  what it says — every field line that enters a closed surface must leave it, so field
  lines close on themselves — and, just as important, what it does not say, since flux
  through an open surface is generally nonzero.
topics: [Magnetic Sources]
draft: false
sources:
  - book: Tipler & Mosca
    ref: "Ch. 27 — Sources of Magnetic Fields; §27-3 Gauss’s Law for Magnetism"
---

## Closed-surface magnetic flux

Magnetic flux through an oriented surface $S$ is

$$
\Phi_B=\int_S\vec B\mathbin{\cdot}\d\vec A.
$$

The area element $\d\vec A$ is normal to the surface. An open surface requires
its orientation to be chosen and stated; reversing the normal reverses the flux sign.
The standard orientation of a closed surface points outward. Gauss's law for
magnetism states

$$
\oint_S\vec B\mathbin{\cdot}\d\vec A=0.
$$

Every closed surface has zero net magnetic flux. The law does not require magnetic
field to vanish on the surface. A field can enter one region of a closed boundary and
leave another with equal signed flux. The cancellation concerns the surface integral,
not the field magnitude at a single point.

$$
% caption: A uniform magnetic field through a closed box. Whatever flux enters the
% inward-facing left side leaves the outward-facing right side, and the four faces
% parallel to the field carry none, so the net flux over the whole surface is zero
% even though the field is nonzero throughout.
\begin{tikzpicture}[>=stealth,font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\draw[black,thick] (1.40,0.80) rectangle (3.60,2.40);
\draw[black,thick] (1.40,2.40)--(2.10,2.90)--(4.30,2.90)--(3.60,2.40);
\draw[black,thick] (3.60,0.80)--(4.30,1.30)--(4.30,2.90);
\draw[black,dashed] (1.40,0.80)--(2.10,1.30)--(4.30,1.30);
\draw[black,dashed] (2.10,1.30)--(2.10,2.90);
\foreach \y in {1.15,1.60,2.05} {
  \draw[->,acc,very thick] (0.55,\y)--(5.10,\y);
}
\node[below] at (1.70,0.74) {inward face};
\node[below] at (3.95,0.74) {outward face};
\node[above] at (2.85,2.92) {closed surface};
\end{tikzpicture}
$$

A uniform field of magnitude $B$ through a rectangular box can be taken parallel
to the $x$ direction. The right face has outward normal
$+\hat x$, contributing $+BA$, and the left face has outward normal
$-\hat x$, contributing $-BA$. The remaining four faces have normals
perpendicular to $\vec B$, so each contribution is zero. Summing all six
contributions gives zero. This simple calculation checks the area-vector sign
convention before more complicated surface geometry is used.

An open surface can have nonzero flux. A circular loop in a uniform field has
$\Phi_B=BA\cos\theta$ when the field makes angle $\theta$ with the loop's chosen
normal. Closing the loop with an imaginary surface elsewhere adds surface pieces
whose flux balances the first one. Confusing an open loop flux with a
closed-surface flux is a common source of an incorrect nonzero result for Gauss's law.

### Field-line continuity and the absence of magnetic charge

Electric field lines can begin on positive charge and end on negative charge. A
magnetic field map has a different topology. Magnetic field lines have no isolated
beginning or end within the classical field description. A line that emerges from
the north-seeking end of a bar magnet continues through the surrounding region,
returns to the south-seeking end, and closes through the magnet's interior. The
labels north and south describe the exterior pattern; they do not identify separate
magnetic charges.

$$
% caption: Magnetic field lines of a bar magnet close on themselves. Each exterior
% curve leaves the north end, arcs through the surrounding space, and enters the
% south end; the interior return then carries it back, so no line has an isolated
% start or finish.
\begin{tikzpicture}[>=stealth,font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\fill[acc!12] (3.45,1.15) rectangle (6.05,2.05);
\draw[black,thick] (3.45,1.15) rectangle (6.05,2.05);
\draw[black] (4.75,1.15)--(4.75,2.05);
\node at (4.10,1.82) {S};
\node at (5.40,1.82) {N};
\draw[->,acc,thick] (6.00,2.00) .. controls (5.30,3.00) and (4.20,3.00) .. (3.50,2.00);
\draw[->,acc,thick] (6.05,2.03) .. controls (6.80,3.65) and (2.70,3.65) .. (3.45,2.03);
\draw[->,acc,thick] (6.00,1.20) .. controls (5.30,0.20) and (4.20,0.20) .. (3.50,1.20);
\draw[->,acc,thick] (6.05,1.17) .. controls (6.80,-0.45) and (2.70,-0.45) .. (3.45,1.17);
\draw[->,black,thick] (3.75,1.42)--(5.75,1.42);
\node[left] at (2.05,2.60) {exterior line};
\node[below] at (4.75,1.09) {interior return};
\end{tikzpicture}
$$

Gauss's law expresses this continuity in integral form. A closed surface around one
end of a magnet is still crossed by magnetic field lines that continue through the
surface elsewhere. A sufficiently large surface around the entire magnet contains
both outgoing and incoming crossings. Changing the surface shape can change local
flux density and the locations where lines cross, but the signed total remains zero.

The divergence theorem converts the surface law into the differential form

$$
\oint_S\vec B\mathbin{\cdot}\d\vec A
=\int_V\left(\nabla\mathbin{\cdot}\vec B\right)\d\tau
=0,
\qquad
\nabla\mathbin{\cdot}\vec B=0.
$$

The divergence condition is local. It says that the net outward magnetic flux from
an arbitrarily small closed volume is zero. A magnetic field may curve, vary in
magnitude, and have nonzero curl while remaining divergence-free. Divergence and
curl measure different local properties and should not be interchanged.

No isolated magnetic monopole has been established in the classical experiments
covered here. A hypothetical monopole of magnetic charge $g$ would change the
closed-surface law to a nonzero flux proportional to enclosed $g$, analogous to
electric Gauss's law. The observed zero law constrains the usual magnetic sources:
currents, moving charges, and magnetized material produce fields with continuous
lines rather than radial source or sink patterns.

### Surface choice and flux bookkeeping

The closed surface used in Gauss's law is an accounting boundary, not a physical
shell. It can be spherical, cubical, irregular, or assembled from several patches.
Choose a surface that makes the flux contributions easy to identify. An ideal
solenoid can be enclosed by a long narrow cylinder that contains strong nearly axial field
and a region of weak exterior field; the end caps account for the corresponding
entering and leaving flux. A pillbox around a circular current loop intersects field
lines in different directions across its faces, but the sum remains zero.

The sign of an individual flux contribution follows from the dot product. A field
pointing outward through an outward-oriented patch contributes positive flux. The
same field pointing inward contributes negative flux. A field tangent to the patch
contributes zero flux. Sketching the outward normal on every surface patch is more
reliable than assigning signs from the left or right side of a page drawing.

Flux cancellation can occur between large contributions. A numerical surface
integral should therefore store signed contributions and sum them before taking any
magnitude. Reporting the absolute flux through each face and then adding the values
destroys the cancellation required by Gauss's law. A relative residual

$$
\eta_\Phi=
\frac{\left|\sum_j\Phi_{B,j}\right|}
{\sum_j|\Phi_{B,j}|}
$$

is a practical check for a discretized closed surface. A small value indicates cancellation
within the mesh and measurement precision; it does not establish that the underlying
field source has been identified correctly.

### Normal component at a material boundary

Apply a thin closed pillbox across any ordinary magnetic boundary. As the pillbox
height tends to zero, flux through its curved side vanishes relative to flux through
the two faces. Gauss's law then gives

$$
B_{n,2}-B_{n,1}=0.
$$

The normal component of $\vec B$ is continuous across the boundary. The
statement holds whether the regions are vacuum, air, or magnetic media. The tangential
component can change when surface current or material magnetization is present; its
boundary condition is a separate result from Ampère's law.

$$
% caption: A thin pillbox straddling a magnetic-material boundary. As its height
% shrinks, only the two flat faces carry flux, and Gauss's law forces the flux in
% to equal the flux out — the normal component of B is continuous across the
% interface even when the field tilts on crossing it.
\begin{tikzpicture}[>=stealth,font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\fill[acc!8] (0.50,1.40) rectangle (5.50,2.60);
\fill[black] (0.50,0.20) rectangle (5.50,1.40);
\draw[black,thick] (0.50,1.40)--(5.50,1.40);
\draw[black,dashed] (2.30,0.80) rectangle (3.70,2.00);
\draw[->,acc,very thick] (2.90,0.40)--(2.90,2.45);
\node at (1.35,0.72) {region one};
\node at (1.35,2.12) {region two};
\node[right] at (3.90,1.16) {interface};
\node[right] at (3.78,1.92) {pillbox};
\node[right] at (2.98,2.28) {normal B};
\end{tikzpicture}
$$

The normal-component condition is a local check for a field map. Draw a small
boundary-normal arrow at corresponding points on either side, then compare the
normal components after accounting for the coordinate convention. A discontinuity
in the plotted normal component signals a measurement calibration error, an
unresolved source current crossing the pillbox, or a calculation that violates the
divergence-free condition.

### Measuring a closed-surface flux balance

Magnetic probes usually measure one component at a time. A closed-surface flux test
can be built from measurements on a tessellated surface. Divide the surface into
small patches with known outward area vectors $\Delta\vec A_j$, measure or
estimate the field vector at each patch centre, and form

$$
\Phi_B^{\rm mesh}
=\sum_j\vec B_j\mathbin{\cdot}\Delta\vec A_j.
$$

Refine the patch spacing until the signed sum and its uncertainty stabilize. A probe
with a fixed sensing axis must be rotated or the apparatus transformed to obtain the
normal component on each patch. Background fields require the same treatment:
include them consistently on all patches or subtract a separately measured
background map before forming the sum.

The test has practical limits. A sparse mesh can miss rapid spatial variation near a
wire, magnet edge, or small coil. Probe orientation error changes the measured normal
component systematically. A surface that passes through a current-carrying conductor
requires a field model with the conductor's finite cross-section, since point samples
near the path may vary sharply. State the mesh geometry, coordinate calibration,
probe axis, patch areas, background procedure, and convergence criterion with any
reported flux residual.

## Flux tubes and surface deformation

A flux tube is bounded by a family of magnetic field lines. Its side wall is tangent
to $\vec B$, so the side-wall contribution to $\vec B\mathbin{\cdot}\d\vec A$
is zero. Take two cross-sections of the same tube and close the region between
them with that tangent wall. Gauss's law gives

$$
\Phi_{B,1}+\Phi_{B,2}=0
$$

when both cross-section normals are chosen outward from the enclosed segment. In a
common coordinate orientation, this says that the signed magnetic flux through one
cross-section equals the signed flux through the other after their normals have been
made parallel. Field magnitude and cross-sectional area compensate:

$$
B_{\perp,1}A_1=B_{\perp,2}A_2
$$

when each cross-section has nearly uniform normal field. A narrowing tube has
larger field magnitude; a widening tube has smaller field magnitude. The relation
describes the same continuous field lines passing through different areas. It is not
a statement that a finite number of lines has been conserved.

$$
% caption: A magnetic flux tube bounded by field lines. Its side wall is tangent to
% the field, so all the flux passes through the two end sections; where the tube
% narrows the same flux crosses a smaller area, so the field there is stronger.
\begin{tikzpicture}[>=stealth,font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\draw[black,thick] (0.75,2.60) .. controls (2.20,2.35) and (3.60,1.95) .. (5.30,1.85);
\draw[black,thick] (0.75,0.70) .. controls (2.20,0.95) and (3.60,1.35) .. (5.30,1.45);
\draw[black,dashed] (0.75,0.70)--(0.75,2.60);
\draw[black,dashed] (5.30,1.45)--(5.30,1.85);
\foreach \x in {1.15,1.95,2.75,3.55,4.35} {
  \draw[->,acc,very thick] (\x,1.65)--(\x+0.50,1.65);
}
\node[left] at (0.70,1.65) {wide end};
\node[right] at (5.35,1.65) {narrow end};
\node[above] at (1.85,2.55) {tangent wall};
\end{tikzpicture}
$$

The construction is local and geometric. It applies to a map of a solenoid,
current loop, or magnetized object wherever a set of nearby field lines can be
identified. It does not say that $\vec B$ is constant along a field line.
Curvature, surrounding currents, and material response can change both direction
and magnitude. The tube relation identifies only the normal flux through selected
cross-sections.

In a numerical map, draw a narrow tube through neighboring vector arrows and
estimate cross-sectional area with a short normal segment. Compare
$B_\perp A$ at several locations. A systematic drift may reflect interpolation
error, poor sensor orientation, or a tube boundary that no longer follows the local
field. It can also indicate that the sampled surface crosses an unresolved current
or magnetic material boundary, where a finer physical model is required.

### Deforming a closed surface without changing its flux balance

Closed-surface flux is unchanged when an accounting surface is smoothly deformed
through a region where $\nabla\mathbin{\cdot}\vec B=0$. The local
field crossings rearrange as the surface moves, yet the signed sum remains zero for
every closed version of the surface. A sphere around a current loop, a rounded box
around the same loop, and a wrinkled laboratory scan surface all give zero net
magnetic flux if each is complete and the field is evaluated accurately.

$$
% caption: The same current loop enclosed by two different closed surfaces. Because
% the field between them is divergence-free, a smooth surface and a deformed one
% record the same zero net flux; only the local crossings rearrange.
\begin{tikzpicture}[>=stealth,font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\draw[black,dashed] (1.60,1.60) circle (1.15);
\draw[acc,very thick] (1.60,1.60) ellipse (0.55 and 0.22);
\draw[->,acc,thick] (2.10,1.68) arc (12:168:0.55 and 0.22);
\draw[black,dashed] plot[smooth cycle] coordinates {(4.50,2.90) (5.40,2.20) (5.50,1.35) (5.00,0.50) (4.10,0.45) (3.40,1.25) (3.55,2.15)};
\draw[acc,very thick] (4.50,1.60) ellipse (0.55 and 0.22);
\draw[->,acc,thick] (5.00,1.68) arc (12:168:0.55 and 0.22);
\node[below] at (1.60,0.30) {round surface};
\node[below] at (4.45,0.25) {deformed surface};
\node[above] at (3.05,3.05) {same loop enclosed};
\end{tikzpicture}
$$

The surface cannot be deformed across a singular model source without changing what
the mathematical field model represents locally. A filamentary current path has an
idealized singularity at its centreline. In practical work, give the conductor a
finite radius and avoid claiming pointwise field values on the current itself.
Gauss's law still applies to a closed surface around that finite conductor; the
warning concerns numerical evaluation of the field near a singular line model.

Open-surface flux behaves differently. Tilting or bending an open surface changes
the area vectors exposed to the field and generally changes $\Phi_B$. Faraday's
law uses this open-surface flux together with a boundary loop and a chosen
orientation. Gauss's law uses a complete boundary-free surface. Keeping those two
uses separate prevents a field-map sketch from assigning the same flux value to
surfaces with different boundaries.

### Differential map checks on a finite grid

A sampled magnetic map can be checked cell by cell. A rectangular cell of volume
$\Delta x\,\Delta y\,\Delta z$ gives a divergence approximation using face-centred
components:

$$
(\nabla\mathbin{\cdot}\vec B)_{\rm cell}
\simeq
\frac{B_x^{+}-B_x^{-}}{\Delta x}
+\frac{B_y^{+}-B_y^{-}}{\Delta y}
+\frac{B_z^{+}-B_z^{-}}{\Delta z}.
$$

The superscripts label opposite faces, not positive and negative field values. A
small value means that the signed fluxes through the six faces balance within grid
and measurement error. It does not mean that all six components are small. A uniform
field has nonzero components and zero discrete divergence because opposite face
values are equal.

Finite differences require a stated resolution. If the cell is large compared with
the scale on which $\vec B$ changes, opposite-face averages cannot resolve strong
internal variation. If the cell is extremely small, sensor noise divided by a short
distance can dominate the estimated derivative. Use a coarse map to locate rapid
variation, then refine locally and compare the divergence residual across more than
one cell size.

Boundary cells need separate handling. A one-sided derivative near the edge has a
different truncation error from a centred derivative. A cell that straddles a
conductor, magnetic material, or region inaccessible to the probe should be labelled
as a model boundary rather than silently filled with interpolated values. Such
discipline makes a zero-divergence result traceable to measured data and stated
interpolation choices.

> **Worked example (Flux balance in a uniform field).** A uniform field
> $\vec B=(0.600\ \mathrm{mT})\,\hat x$ threads a rectangular box whose faces normal to
> $x$ each have area $A_{yz}=0.0200\ \mathrm{m^2}$. The two $x$-faces carry
>
> $$
> \Phi_{x,+}=+(0.600\times10^{-3})(0.0200)=+1.20\times10^{-5}\ \mathrm{Wb},\qquad
> \Phi_{x,-}=-1.20\times10^{-5}\ \mathrm{Wb},
> $$
>
> with the sign set by the outward normal: field enters one $x$-face and leaves the
> other. The four side faces have their normals perpendicular to $\vec B$, so they
> carry no flux. The net is
> $\Phi_{x,+}+\Phi_{x,-}=0$, as $\oint\vec B\cdot\d\vec A=0$ demands. Reporting
> $2.40\times10^{-5}\ \mathrm{Wb}$ would mean the two face fluxes were added as
> magnitudes, discarding the outward-normal sign.

## Magnetic sources and field topology

Far from a compact current loop, the magnetic field has dipole form.

> **Worked example (Dipole flux through a sphere is zero).** A magnetic dipole $\vec m$
> sits at the centre of a sphere of radius $r$, polar axis along $\vec m$. The radial
> field on the sphere is $B_r=(\mu_0/4\pi)(2m\cos\theta)/r^3$, positive over one
> hemisphere and negative over the other. With $\d A=r^2\sin\theta\,\d\theta\,\d\phi$,
>
> $$
> \Phi_B=\int_0^{2\pi}\!\!\int_0^\pi B_r\,r^2\sin\theta\,\d\theta\,\d\phi
> =\frac{\mu_0 m}{2r}\int_0^\pi \cos\theta\sin\theta\,\d\theta=0,
> $$
>
> since $\int_0^\pi\cos\theta\sin\theta\,\d\theta=\big[\tfrac12\sin^2\theta\big]_0^\pi=0$.
> The zero comes from angular cancellation, not a vanishing field: the sphere's outward
> flux on the $\cos\theta>0$ side exactly cancels the inward flux on the other. Get the
> same sign over the whole sphere and you have accidentally drawn the radial field of an
> electric charge, not a magnetic dipole.

$$
% caption: The field of a magnetic dipole crossing a sphere centred on it. Over the
% upper hemisphere the radial field points outward; over the lower it points inward.
% The two contributions cancel exactly, so the net flux through the whole sphere is
% zero although the field is nonzero everywhere on it.
\begin{tikzpicture}[>=stealth,font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\draw[black,thick] (2.90,1.70) circle (1.40);
\filldraw[draw=black,fill=black!8] (2.90,1.70) circle (0.06);
\draw[->,black,thick] (2.90,1.70)--(2.90,2.30);
\node[right] at (2.95,2.05) {m};
\foreach \a in {55,90,125} {
  \draw[->,acc,very thick] ($(2.90,1.70)+(\a:1.15)$)--($(2.90,1.70)+(\a:1.95)$);
}
\foreach \a in {235,270,305} {
  \draw[->,acc,very thick] ($(2.90,1.70)+(\a:1.95)$)--($(2.90,1.70)+(\a:1.15)$);
}
\node[above] at (2.90,3.85) {outward};
\node[below] at (2.90,-0.50) {inward};
\node[right] at (4.35,1.20) {sphere};
\end{tikzpicture}
$$

The calculated flux checks a far-field model of a current loop. The
field magnitude should decrease strongly with radius, yet the flux balance remains
zero at every radius. A calculation that produces the same-sign radial component
over a complete sphere has adopted a radial-source pattern appropriate to electric
charge, not to an ordinary magnetic dipole.

### Finite solenoids and exterior return paths

An ideal infinitely long solenoid is often drawn with magnetic field confined to its
interior. A finite solenoid has an exterior return field. Field lines leave one end,
curve through the surrounding space, and enter the other end, completing continuous
paths. A closed surface that intersects the interior axial field must also intersect
the exterior return field or have other surface patches whose flux provides the
balance.

$$
% caption: The field of a finite solenoid. Interior arrows run along the axis, and
% exterior curves carry each line from one end back to the other, so the lines close.
% A closed surface cutting the interior field must also cross the exterior return.
\begin{tikzpicture}[>=stealth,font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\draw[black,thick] (1.50,1.20) rectangle (4.80,2.30);
\foreach \x in {1.75,2.05,2.35,2.65,2.95,3.25,3.55,3.85,4.15,4.45} {
  \draw[black] (\x,1.20)--(\x,2.30);
}
\foreach \x in {1.80,2.55,3.30,4.05} {
  \draw[->,acc,very thick] (\x,1.75)--(\x+0.55,1.75);
}
\draw[->,acc,thick] (4.80,2.25) .. controls (6.15,3.35) and (0.15,3.35) .. (1.50,2.25);
\draw[->,acc,thick] (4.80,1.25) .. controls (6.15,0.15) and (0.15,0.15) .. (1.50,1.25);
\node[above] at (3.15,2.32) {coil};
\node at (3.15,1.42) {interior B};
\node[above] at (3.15,2.82) {exterior return};
\end{tikzpicture}
$$

The infinite-solenoid model is a local approximation to the central interior
region of a long winding. It simplifies the field magnitude there but does not
alter Gauss's law. An accounting surface surrounding a finite portion of the
interior must still be closed. If its side wall is selected to follow field lines,
the end caps have opposite signed flux. If the side wall cuts through curved
exterior field, that side contribution must be retained.

A field probe scan along the solenoid axis can check this topology. The central
interior component is large and nearly uniform for a long coil, falls near the ends,
and changes character outside the winding. A one-dimensional axial scan alone does
not measure the exterior return path. Add transverse scans outside the end regions
before using the map to estimate a closed-surface flux balance.

### Cutting a magnet and the scale of a field map

Dividing a bar magnet into shorter pieces does not expose an isolated north end or
south end. Each piece has an exterior pattern with two ends and an interior return
path. The microscopic current and material description of a magnet is treated
separately; the field-map consequence is already fixed by the closed-surface
law. A small Gaussian surface around one cut piece has equal incoming and outgoing
magnetic flux.

$$
% caption: Cutting a bar magnet does not free a pole. Each shorter piece is again a
% full dipole, with its own north and south ends and its own closing field lines;
% no fragment carries isolated magnetic charge.
\begin{tikzpicture}[>=stealth,font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\fill[acc!12] (0.70,1.35) rectangle (2.40,2.15);
\fill[acc!12] (3.70,1.35) rectangle (5.40,2.15);
\draw[black,thick] (0.70,1.35) rectangle (2.40,2.15);
\draw[black,thick] (3.70,1.35) rectangle (5.40,2.15);
\draw[black] (1.55,1.35)--(1.55,2.15);
\draw[black] (4.55,1.35)--(4.55,2.15);
\node at (1.15,1.92) {S};
\node at (1.95,1.92) {N};
\node at (4.15,1.92) {S};
\node at (4.95,1.92) {N};
\draw[->,acc,thick] (2.35,2.10) .. controls (1.90,2.75) and (1.20,2.75) .. (0.75,2.10);
\draw[->,acc,thick] (5.35,2.10) .. controls (4.90,2.75) and (4.20,2.75) .. (3.75,2.10);
\draw[->,black,thick] (0.95,1.55)--(2.15,1.55);
\draw[->,black,thick] (3.95,1.55)--(5.15,1.55);
\draw[black,dashed] (3.05,1.15)--(3.05,2.35);
\node[below] at (1.55,1.29) {piece one};
\node[below] at (4.55,1.29) {piece two};
\node[above] at (3.05,2.35) {cut};
\end{tikzpicture}
$$

The field scale changes as source size and observation distance change. A probe held
at the same absolute distance from a shorter piece can move from a far-field regime
into a near-field regime. Compare maps using dimensionless position such as distance
divided by magnet length when the question concerns shape, and retain physical units
when the question concerns sensor response or flux uncertainty.

### Orientation errors in a surface-flux measurement

A component probe measures $\vec B\mathbin{\cdot}\hat n_{\rm probe}$.
If its sensing axis is tilted by a small angle $\delta$ away from the intended
surface normal, the measured normal component includes a projection error. For a
field parallel to the intended normal,

$$
B_{\rm meas}=B\cos\delta
\simeq B\left(1-\frac{\delta^2}{2}\right).
$$

When the field also has a tangential component, a small tilt introduces a
first-order contamination from that tangential field. The sign depends on the tilt
direction. Calibrate probe orientation at every strongly curved surface region;
using one fixed laboratory axis for all patches produces a false flux residual when
the patch normals vary.

Record probe orientation together with position. A three-axis instrument can be
projected onto each local normal after a coordinate calibration. A single-axis probe
requires mechanical rotation or a surface fixture. Repeat a subset of patches after
reversing source current; the genuine source field reverses, while a sensor offset
does not. The reversal does not correct a systematic orientation error, but it
separates that geometric error from a static additive background.

### Nonuniform flux balance and topology checks

Gauss's law for magnetism applies to nonuniform fields as directly as to uniform ones.
Consider the divergence-free field

$$
\vec B=a x\,\hat x-a y\,\hat y,
$$

over a rectangular closed surface with $0\le x\le L_x$, $0\le y\le L_y$, and
$0\le z\le L_z$. The field magnitude and direction change across the surface, so a
single area times one representative field value is not a valid flux calculation.
Decompose the closed-surface integral into its six planar faces and use the local
outward normal on each face.

On the two faces normal to the x direction, the left face at $x=0$ contributes zero,
while the right face at $x=L_x$ contributes

$$
\Phi_x=(aL_x)L_yL_z.
$$

On the y-normal faces, the lower face at $y=0$ contributes zero. At $y=L_y$, the
field is $-aL_y\hat y$ and the outward normal is
$+\hat y$, giving

$$
\Phi_y=(-aL_y)L_xL_z.
$$

The z-normal faces contribute zero because the field has no z component. Thus
$\Phi_x+\Phi_y=0$. The cancellation is not accidental: the x component increases
with x while the y component decreases with y by the same rate. The differential
check gives $\nabla\!\cdot\!\vec B=a-a=0$, consistent with the complete face sum.

$$
% caption: Face-by-face flux for the divergence-free field B = a x x-hat minus a y
% y-hat over a box. The right face carries outward flux and the top face carries an
% equal inward flux; the other four faces contribute nothing, so the six-face sum
% is zero, matching div B = 0.
\begin{tikzpicture}[>=stealth,font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\draw[black,thick] (1.20,0.80) rectangle (3.80,3.00);
\draw[->,acc,very thick] (3.80,1.90)--(4.70,1.90);
\draw[->,black,very thick] (2.50,3.00)--(2.50,2.10);
\node[right] at (4.75,1.90) {outward};
\node[above] at (2.50,3.06) {inward};
\node[left] at (1.15,1.90) {zero here};
\node[below] at (2.50,0.74) {closed box};
\end{tikzpicture}
$$

A sign audit lists the field component, face location, outward normal, area, and face
contribution on separate lines. Assign each face its own normal, record the sign of
every contribution, and then form the total. A result with two positive contributions
from the displayed x and y faces usually signals that the upper-face normal or the y
component sign was dropped. Units provide a second check: every face contribution must
have units of tesla square metres.

Magnetic topology through a current loop is continuous. A loop current produces field
that passes through the loop interior and returns through the surrounding region.
Field lines can be drawn densely near the loop axis and more broadly outside, but they
do not start at the wire and terminate elsewhere. The wire changes the curl of the
field in its neighbourhood; it does not supply a magnetic line endpoint. A closed map
that clips the exterior return region can make the interior field look one-sided, so
the map boundary and any excluded volume must be stated.

Mesh convergence reports whether a numerical flux estimate is controlled by the grid.
Partition a closed surface into patches, evaluate the normal component on each patch,
multiply by patch area, and sum. Repeat after halving characteristic patch width. The
difference between successive estimates is a numerical-resolution indicator, not a
replacement for instrument uncertainty. Probe offset, orientation uncertainty, source
current uncertainty, and patch-coordinate uncertainty must be propagated separately.

A field satisfying Gauss's law has a signed closed-surface sum that approaches zero
as the mesh is refined until measurement noise dominates. Individual face sums need
not approach zero; their cancellation is the test. Track the largest positive and
negative face contributions as well as the total. A small total formed by two large
poorly measured terms may have a larger uncertainty than a map with smaller individual
terms. State both the total and its uncertainty interval.

A closed-surface result requires a geometry record and independent local checks.
Record surface orientation, patch areas, probe axes, source-current setting,
face-by-face contributions, mesh sequence, and uncertainty model. A current-loop
topology map also states the mapped volume and the region excluded by the measurement
boundary.

| test | quantity held fixed | diagnostic result |
|---|---|---|
| box-size scaling | field model and all but one box length | cancelling face terms scale with the corresponding face area |
| current reversal | probe coordinates and instrument settings | reversible source field changes sign; static background does not |
| mesh refinement | source current, probe height, and surface geometry | numerical change falls to the propagated uncertainty floor |
| local comparison | selected face points and loop-axis points | measured normal component agrees with the model within combined uncertainty |

A reversal pair separates the reversible source field from the static background
with

$$
\vec B_{\mathrm{src}}
=\frac{\vec B_{+I}-\vec B_{-I}}{2},
\qquad
\vec B_{\mathrm{bg}}
=\frac{\vec B_{+I}+\vec B_{-I}}{2}.
$$

The probe-coordinate system remains fixed during this comparison. The source vectors
should reverse; an offset that remains unchanged belongs to the instrument or
background field.

- **Nonuniform-box scaling.** Increase $L_x$ while holding the other dimensions
  fixed. The positive x-face and negative y-face terms grow in proportion to
  $L_x$, so their cancellation persists. Increase $L_z$: both nonzero face
  contributions acquire the same factor. A missing length in one area breaks these
  tests and exposes a unit or geometry error.
- **Topology boundary.** A finite box can have field entering one side and leaving
  another while no field line endpoint lies inside it. The closed-surface sum tests
  all faces. A two-dimensional line plot does not specify the three-dimensional
  surface used for that sum.
- **Convergence record.** For each mesh, retain total flux, positive-face subtotal,
  negative-face subtotal, and propagated uncertainty. A decreasing numerical
  difference followed by a plateau at the uncertainty floor supports convergence.
  Oscillation or continued drift after refinement can indicate coordinate
  registration error, probe interpolation bias, or a changing source field.
- **Correlations and local checks.** A common probe-gain factor shifts many patches
  together and does not average away. Repeated independent noise can decrease with
  sampling, whereas a shared orientation offset rotates every normal component.
  For a worked map, compare the measured and modeled normal component at one point
  on each nonzero face, near the loop axis, and in the exterior return region.
  Report each residual in units of its combined uncertainty.

A map that passes the local component checks and the closed-surface convergence
check supports both the measured field components and their topology. A field-line
drawing alone provides neither numerical test.

At a selected surface patch, reduce the component comparison to a signed normalized
residual,

$$
r_n=\frac{B_{n,\mathrm{meas}}-B_{n,\mathrm{model}}}
{\sqrt{\sigma_{n,\mathrm{meas}}^2+\sigma_{n,\mathrm{model}}^2}}.
$$

Use the same normal orientation in the data reduction and the model. A sequence of
residuals with one common sign across a face indicates gain, coordinate, or normal
orientation bias; alternating residuals at the scale of patch spacing can indicate
interpolation or probe-position error. The face residuals and the total closed-surface
sum test different claims, so retain both in the map record.

Repeat the residual calculation after rotating the probe through the stated normal
orientation and after reversing the source current. A residual that changes sign with
the source belongs to the source-field comparison; one that remains fixed can arise
from probe offset, background field, or coordinate registration. This paired record
prevents a small closed-surface sum from being accepted when one face carries a
systematic normal-component bias.

Keep the face areas and normal vectors at full recorded precision until the final
flux sum. Rounding each contribution before cancellation can create an apparent
nonzero flux or conceal a coordinate error. A reproducible calculation stores the
unrounded face terms, their covariance assumptions, and the final rounded result
separately.

## Divergence and diagnostic checks

The statement $\nabla\mathbin{\cdot}\vec B=0$ has the same physical
meaning in every coordinate system, but component derivatives carry geometric scale
factors. In cylindrical coordinates,

$$
\nabla\mathbin{\cdot}\vec B
=\frac{1}{r}\frac{\partial(rB_r)}{\partial r}
+\frac{1}{r}\frac{\partial B_\phi}{\partial\phi}
+\frac{\partial B_z}{\partial z}.
$$

An ideal long straight current has an external magnetic field with azimuthal
component $B_\phi(r)$, no radial or axial component, and no dependence on
$\phi$. Every term in the cylindrical divergence is then zero. The field can vary
strongly with radius and still have zero divergence because the variation is in a
component tangent to cylindrical surfaces, not in a radial source component.

A long axial solenoid has a central approximation with $B_z$ nearly constant,
$B_r\simeq0$, and negligible $z$ derivative over a short central interval.
The divergence is again zero. Near a finite solenoid end, radial and axial components
both occur. A field map must retain both terms; applying the central uniform-field
approximation to the end region discards the radial return that completes the
closed-line topology.

In spherical coordinates, a radial field component contributes

$$
\nabla\mathbin{\cdot}\vec B
=\frac{1}{r^2}\frac{\partial(r^2B_r)}{\partial r}
+\frac{1}{r\sin\theta}
\frac{\partial(\sin\theta B_\theta)}{\partial\theta}
+\frac{1}{r\sin\theta}\frac{\partial B_\phi}{\partial\phi}.
$$

The dipole field combines radial and polar components whose derivatives cancel.
Checking only $B_r$ would give a false nonzero divergence. This is a recurring
calculation error: a curved coordinate basis changes direction from point to point,
so the derivative of a vector field includes geometric effects as well as changes in
the displayed component magnitude.

Coordinate choices should be documented with measured maps. A three-axis probe
returns components in its own laboratory axes. Transform those components into
cylindrical or spherical directions at every map point before applying a symmetry
formula. A probe kept parallel to one laboratory axis does not directly measure
$B_r$, $B_\phi$, or $B_\theta$ everywhere on a curved surface.

### Local zero divergence and excluded model singularities

The differential law applies where the magnetic field model is regular. A filament
current is an idealization with an undefined field at its centreline. An experiment
has a conductor with finite radius, current distribution, insulation, and a finite
probe standoff. Model the field outside the conductor with the appropriate symmetry
expression and treat the interior using the stated current-density model when a
surface passes through it.

The difference between an excluded singular line and an isolated magnetic charge is
important. A mathematical azimuthal field around a filament wire has a line at which
the exterior coordinate formula is undefined. Its field lines circle the line and
have no normal flux through a small cylinder around it. A radial point-source field
would instead carry outward normal flux through a small sphere. Ordinary current
sources have the first topology; magnetic monopoles would have the second. Excluding
a wire centreline from a numerical mesh does not create a magnetic charge.

$$
% caption: Why ordinary sources never break Gauss's law. Around a current-carrying
% wire the field circulates, staying tangent to the enclosing surface, so its net
% flux is zero. A magnetic monopole would instead radiate outward and pierce the
% surface, giving nonzero flux; no such source is observed.
\begin{tikzpicture}[>=stealth,font=\footnotesize]
\definecolor{acc}{HTML}{4A6FA5}
\draw[black,dashed] (1.60,1.60) circle (0.95);
\filldraw[draw=black,fill=black!8] (1.60,1.60) circle (0.06);
\draw[->,acc,very thick] ($(1.60,1.60)+(90:0.70)$) arc (90:12:0.70);
\draw[->,acc,very thick] ($(1.60,1.60)+(0:0.70)$) arc (0:-78:0.70);
\draw[->,acc,very thick] ($(1.60,1.60)+(270:0.70)$) arc (270:192:0.70);
\draw[->,acc,very thick] ($(1.60,1.60)+(180:0.70)$) arc (180:102:0.70);
\node[above] at (1.60,2.75) {stays tangent};
\node[below] at (1.60,0.45) {current source};
\draw[black,dashed] (4.90,1.60) circle (0.95);
\filldraw[draw=acc,fill=acc!12] (4.90,1.60) circle (0.06);
\foreach \a in {30,90,150,210,270,330} {
  \draw[->,black,thick] (4.90,1.60)--($(4.90,1.60)+(\a:1.20)$);
}
\node[above] at (4.90,2.75) {pierces surface};
\node[below] at (4.90,0.45) {monopole source};
\end{tikzpicture}
$$

A numerical divergence calculation needs a declared domain. Do not form a centred
finite difference across an inaccessible wire, a metal boundary, or a large gap in
the measurement grid. Mark that region as excluded, use one-sided derivatives only
with their larger truncation uncertainty, or compute an integral flux over a surface
that stays in the resolved domain. A small residual near an excluded region has less
diagnostic value than a small residual in a fully sampled volume.

### Interpreting a nonzero closed-surface residual

Three classes of cause can produce an estimated nonzero flux.

- **Orientation or sign error:** one or more patch normals point inward in the
  calculation, a probe polarity is reversed, or a coordinate transformation has an
  inconsistent handedness.
- **Resolution or interpolation error:** patch size is too large near a gradient,
  a curved surface is represented by flat areas too coarsely, or missing components
  are filled with an unsupported interpolation.
- **Model or apparatus error:** the mapped current path differs from the drawing,
  a nearby ferromagnetic object distorts the field, the source current drifts, or a
  probe is measuring outside its calibrated range.

Diagnose these causes in order. Reverse source current and recompute the current-odd
map. A sign or coordinate error often remains tied to one patch orientation, while a
genuine source field reverses consistently. Refine the surface mesh without changing
the physical apparatus. A numerical residual that shrinks with patch size is a
resolution issue. Finally, move or shield a suspected external object and repeat
the same map with the same coordinate survey. A persistent spatially localized
residual points to source geometry or material response.

Report the residual relative to the sum of absolute patch fluxes as well as in
webers. A small number of webers can be significant for a weak source and
insignificant beside large cancelling face fluxes. Quote the measurement uncertainty
of the signed sum, including common calibration terms that correlate many patches.
The comparison belongs to zero within that uncertainty interval; rounding the
individual patch values before summation can create a false residual.

The reporting record should identify whether the test used a measured vector field,
a model field, or a mixture. A model may satisfy zero divergence algebraically while
the apparatus does not match its source geometry. A measured map can have a
zero-compatible surface sum while still lacking enough resolution to establish the
near-source field shape. Both checks are required when Gauss's law is used as a
validation condition for an experimental magnetic map.

### Closed-cylinder test for an azimuthal magnetic map

> **Worked example (Closed cylinder around a wire).** Wrap a closed cylinder of radius
> $R$ and length $L$ around a long straight wire. Outside the wire the field is purely
> azimuthal, $\vec B=B_\phi(r)\,\hat\phi$, with $B_\phi$ possibly varying with radius.
> The curved wall's outward normal is $\hat r$, so
>
> $$
> \vec B\cdot\d\vec A=B_\phi(r)\,\hat\phi\cdot\hat r\,\d A=0
> $$
>
> at every point (since $\hat\phi\perp\hat r$). The end caps have normals $\pm\hat z$,
> also perpendicular to $\hat\phi$. Every patch contributes zero, so the closed-surface
> flux is zero — no large positive and negative face integrals to cancel, and it holds
> whatever the radial law $B_\phi(r)$. Gauss's law is satisfied identically here, and
> for that reason gives no information about $B_\phi(r)$ itself; that takes Ampère's
> law, whose loop element $\d\vec\ell\parallel\hat\phi$ makes $\vec B\cdot\d\vec\ell$
> nonzero.

The surface-flux test differs from the Ampère circulation integral around the same wire. An
Amperian circle has tangent element $\d\vec\ell$ parallel to
$\hat\phi$, so $\vec B\mathbin{\cdot}\d\vec\ell$ is
nonzero around the circle. The Gaussian cylinder has area normals perpendicular to
$\hat\phi$, so $\vec B\mathbin{\cdot}\d\vec A$ is zero. One
geometric path tests circulation; the other tests flux. Switching the dot-product
element changes the physical question.

An experimental map can verify the azimuthal direction before calculating either
integral. Place a three-axis probe at several polar angles on one cylindrical ring.
Transform each recorded vector into radial, azimuthal, and axial components. A
well-aligned long-wire region has dominant azimuthal component and small radial and
axial components within uncertainty. Repeat at several radii. The magnitude can
change substantially between rings while the normal flux through each cylindrical
surface remains zero.

Finite wires, bends, return leads, and nearby magnetic material modify the ideal
map. The measured radial and axial components then need not vanish. A closed surface
around a finite apparatus still has zero net magnetic flux, but some patches carry
positive and negative contributions that must be summed. The all-zero individual
contribution test applies only to the ideal azimuthal geometry. Stating that domain
prevents a convenient long-wire result from being extended to a complete circuit
without its return path.

Use the cylindrical test as an orientation calibration. Reverse current and verify
that the measured azimuthal component reverses at every polar angle. A probe axis
misregistration often appears as an apparent radial component that changes with
angle in the instrument frame. Correct the coordinate transformation before
interpreting that component as a physical violation of cylindrical symmetry. Then
evaluate the signed closed-surface flux from the transformed vector map and compare
it with its propagated uncertainty.

A data table for each ring lists polar angle, radial component, azimuthal component,
axial component, probe orientation, and the uncertainty of each component. Plotting
components against polar angle exposes systematic patterns that
are invisible in a single magnitude trace. A constant axial offset can indicate a
background field. A radial component that follows a sinusoid with polar angle can
indicate a small offset between the probe rotation axis and the wire centreline.
An irregular pattern concentrated near one angle can identify a return lead or a
local piece of magnetic material.

The surface calculation should use the same angular samples that establish the
component map. Associate each sample with a cylindrical patch area
$R\,\Delta\phi\,\Delta z$ and with its outward radial normal. Sum the measured
normal components with signed area weights. A separate end-cap scan provides any
axial flux relevant for a finite cylindrical surface. This procedure carries
the geometric distinction between circulation and flux into the measured-data
analysis instead of leaving it as a symbolic identity.

Keep the wire-centre survey separate from the probe-coordinate survey. A displacement
of the assumed cylindrical axis changes every radial normal and can create a
coherent artificial flux residual even when the measured magnetic vectors are
accurate. Refit the axis from a multi-angle scan, repeat the transformation, and
record the change in the residual as a coordinate-system uncertainty.
The revised surface normals must be used consistently on every sampled patch.
The result then remains comparable across mesh refinements and repeated scans.
All orientations require explicit archival.
