TExcelTAD

The Biot–Savart Law

A current sensor sits 5 mm5\ \text{mm} from a PCB trace; a compass on the bench is 30 cm30\ \text{cm} from a coil; an MRI-style coil pair must hold its field uniform to a fraction of a percent. Each question asks the same thing: given a current path of any shape, what is the magnetic field at a point? The school rule B=μ0I/(2πr)B = \mu_0 I/(2\pi r) (Field of a Straight Wire) covers one infinitely long wire. The Biot–Savart law covers every shape, because it adds up the contribution of each small piece of the path. It is the magnetic counterpart of Coulomb's law (Coulomb's Law and the Electric Field), and in code it is a ten-line function.

The law

I dl R P dHout of page dH = I dl x R / (4 pi |R|^3), perpendicular to dl and R

A current element I dlI\,d\mathbf{l} at a source point produces at the field point a contribution

dH=I dl×R^4πR2=I dl×R4πR3,H=∮I dl×R4πR3d\mathbf{H} = \frac{I\,d\mathbf{l} \times \hat{\mathbf{R}}}{4\pi R^2} = \frac{I\,d\mathbf{l} \times \mathbf{R}}{4\pi R^3}, \qquad \mathbf{H} = \oint \frac{I\,d\mathbf{l} \times \mathbf{R}}{4\pi R^3}

where R\mathbf{R} points from the element to the field point. H\mathbf{H} is the magnetic field intensity in A/m\text{A/m}; in free space the flux density is B=μ0H\mathbf{B} = \mu_0\mathbf{H} in tesla (Ampère's Circuital Law: H and B explains why there are two fields). Three features are worth seeing in the formula:

  • Inverse square, like Coulomb, but the direction is a cross product (The Cross Product): dHd\mathbf{H} is perpendicular to both the current and the line to the point, so field lines circle the current (right-hand rule).
  • An element contributes nothing along its own line (dl∥Rd\mathbf{l} \parallel \mathbf{R}).
  • Only closed circuits are physical for steady currents (∇⋅J=0\nabla \cdot \mathbf{J} = 0); a straight segment's field is a building block that only makes sense summed around a loop.

For distributed currents replace I dlI\,d\mathbf{l} by K dS\mathbf{K}\,dS (surface current) or J dv\mathbf{J}\,dv (volume current).

Three results to remember

Finite straight segment. At perpendicular distance ρ\rho from the line of a segment, with the ends seen at angles α1\alpha_1 and α2\alpha_2 measured from the perpendicular foot (signed),

H=I4πρ(sin⁡α2−sin⁡α1) ϕ^\mathbf{H} = \frac{I}{4\pi\rho}(\sin\alpha_2 - \sin\alpha_1)\,\hat{\boldsymbol{\phi}}

For an infinitely long wire α1→−90∘\alpha_1 \to -90^\circ, α2→90∘\alpha_2 \to 90^\circ, so H=I/(2πρ)H = I/(2\pi\rho).

Circular loop on its axis. A loop of radius aa at height zz below the point:

H=Ia22(a2+z2)3/2 z^,Hcentre=I2a\mathbf{H} = \frac{I a^2}{2(a^2 + z^2)^{3/2}}\,\hat{\mathbf{z}}, \qquad H_\text{centre} = \frac{I}{2a}

Far away (z≫az \gg a) this is H≈2m/(4πz3)H \approx 2m/(4\pi z^3) with the magnetic dipole moment m=Iπa2m = I\pi a^2, the same 1/r31/r^3 fall-off as an electric dipole (Electric Dipoles and Electrostatic Energy).

Off the axis the loop's field needs complete elliptic integrals K(m)K(m) and E(m)E(m), which SciPy provides; the code below checks a numerical sum against them.

Worked example: a square loop

Given: a square loop of side L=10 cmL = 10\ \text{cm} carrying I=1 AI = 1\ \text{A}, in air.

Find: HH and BB at the centre, and compare with a circular loop of radius 5 cm5\ \text{cm} (the inscribed circle).

Solve: each side is at ρ=5 cm\rho = 5\ \text{cm} from the centre, with its ends at α=±45∘\alpha = \pm 45^\circ. The four sides add (all point the same way by the right-hand rule):

Hside=1 A4π⋅0.05 m(sin⁡45∘+sin⁡45∘)=1.592⋅1.414 A/m=2.251 A/mH=4Hside=9.003 A/m,B=μ0H=4π×10−7⋅9.003 T=11.31 μTHcircle=I2a=1 A0.1 m=10 A/m,Bcircle=12.57 μT\begin{aligned} H_\text{side} &= \frac{1\ \text{A}}{4\pi \cdot 0.05\ \text{m}}(\sin 45^\circ + \sin 45^\circ) = 1.592 \cdot 1.414\ \text{A/m} = 2.251\ \text{A/m} \\ H &= 4 H_\text{side} = 9.003\ \text{A/m}, \qquad B = \mu_0 H = 4\pi \times 10^{-7} \cdot 9.003\ \text{T} = 11.31\ \mu\text{T} \\ H_\text{circle} &= \frac{I}{2a} = \frac{1\ \text{A}}{0.1\ \text{m}} = 10\ \text{A/m}, \qquad B_\text{circle} = 12.57\ \mu\text{T} \end{aligned}

Check: the square's wire is 40 cm40\ \text{cm} against the circle's 31.4 cm31.4\ \text{cm}, yet its centre field is 10 % smaller: the square's corners are farther away and the field falls as 1/R21/R^2. Both are about a quarter of the Earth's field (2525 to 65 μT65\ \mu\text{T}), which is why a compass near a 1 A1\ \text{A} loop barely moves.

In Python: a numerical Biot–Savart solver

The function cuts any closed path into straight segments and sums μ0I Δl×R/(4πR3)\mu_0 I\,\Delta\mathbf{l} \times \mathbf{R}/(4\pi R^3) at each segment's midpoint, vectorised with NumPy. It reproduces the square loop, converges to the exact elliptic-integral field of a circular loop at an off-axis point, and then shows why a Helmholtz pair (two coaxial loops one radius apart) is the standard way to make a uniform field.

python · try it yourself
import numpy as np
from scipy.special import ellipk, ellipe
MU0 = 4e-7 * np.pi

def biot_savart(path, I, P):
    """B (T) at point P from a closed polyline path (N x 3, m) carrying I (A)."""
    a, b = path[:-1], path[1:]
    dl, R = b - a, P - 0.5 * (a + b)
    Rn = np.linalg.norm(R, axis=1)[:, None]
    return MU0 * I / (4 * np.pi) * np.sum(np.cross(dl, R) / Rn**3, axis=0)

def loop_path(a, n):
    t = np.linspace(0, 2 * np.pi, n + 1)
    return np.column_stack([a * np.cos(t), a * np.sin(t), np.zeros_like(t)])

def loop_exact(a, I, rho, z):
    """Exact (B_rho, B_z) of a circular loop of radius a in the plane z = 0."""
    q = (a + rho)**2 + z**2
    m = 4 * a * rho / q
    K, E = ellipk(m), ellipe(m)
    d = (a - rho)**2 + z**2
    Bz = MU0 * I / (2 * np.pi * np.sqrt(q)) * (K + (a*a - rho*rho - z*z) / d * E)
    Br = MU0 * I * z / (2 * np.pi * rho * np.sqrt(q)) * (-K + (a*a + rho*rho + z*z) / d * E)
    return Br, Bz

# square loop, side 0.1 m, 1 A, 100 segments per side
c = np.array([[0.05, 0.05, 0], [-0.05, 0.05, 0], [-0.05, -0.05, 0], [0.05, -0.05, 0], [0.05, 0.05, 0]])
square = np.vstack([np.linspace(c[i], c[i + 1], 101)[:-1] for i in range(4)] + [c[:1]])
B = biot_savart(square, 1.0, np.zeros(3))
print(f"square loop centre: Bz = {B[2]*1e6:.3f} uT, hand 2*sqrt(2)*mu0*I/(pi*L) = "
      f"{2*np.sqrt(2)*MU0/(np.pi*0.1)*1e6:.3f} uT")

a, I, P = 0.05, 1.0, np.array([0.03, 0.0, 0.02])     # loop radius 5 cm; point rho = 3 cm, z = 2 cm
for n in (12, 48, 400):
    B = biot_savart(loop_path(a, n), I, P)
    print(f"loop, {n:3d} segments: Brho = {B[0]*1e6:.4f} uT, Bz = {B[2]*1e6:.4f} uT")
Br, Bz = loop_exact(a, I, 0.03, 0.02)
print(f"loop, exact:        Brho = {Br*1e6:.4f} uT, Bz = {Bz*1e6:.4f} uT")

print("Helmholtz pair (loops at z = -a/2 and +a/2), field on the axis:")
z = np.linspace(-0.5 * a, 0.5 * a, 5)
Bpair = [loop_exact(a, I, 1e-12, zi - a/2)[1] + loop_exact(a, I, 1e-12, zi + a/2)[1] for zi in z]
for zi, b in zip(z, Bpair):
    print(f"  z = {zi*1e3:6.1f} mm: Bz = {b*1e6:.3f} uT ({(b / Bpair[2] - 1)*100:+.3f} %)")
square loop centre: Bz = 11.314 uT, hand 2*sqrt(2)*mu0*I/(pi*L) = 11.314 uT
loop,  12 segments: Brho = 5.0335 uT, Bz = 10.3522 uT
loop,  48 segments: Brho = 4.5782 uT, Bz = 10.1535 uT
loop, 400 segments: Brho = 4.5486 uT, Bz = 10.1388 uT
loop, exact:        Brho = 4.5482 uT, Bz = 10.1386 uT
Helmholtz pair (loops at z = -a/2 and +a/2), field on the axis:
  z =  -25.0 mm: Bz = 17.009 uT (-5.418 %)
  z =  -12.5 mm: Bz = 17.908 uT (-0.420 %)
  z =    0.0 mm: Bz = 17.984 uT (+0.000 %)
  z =   12.5 mm: Bz = 17.908 uT (-0.420 %)
  z =   25.0 mm: Bz = 17.009 uT (-5.418 %)

The midpoint sum converges roughly as 1/n21/n^2: 12 segments are 2 % off in BzB_z, 400 segments agree with the exact field to 4 digits. In the Helmholtz pair the first three derivatives of BzB_z vanish at the centre, so the field stays within 0.42 %0.42\ \% over the middle half of the gap; the centre value is (4/5)3/2μ0I/a=17.98 μT(4/5)^{3/2}\mu_0 I/a = 17.98\ \mu\text{T} per ampere-turn.

Guided lab: map the field of a coil

Hand calculation. A flat coil of N=50N = 50 turns, mean radius 5 cm5\ \text{cm}, at I=1 AI = 1\ \text{A}: Bcentre=Nμ0I/(2a)=628 μTB_\text{centre} = N\mu_0 I/(2a) = 628\ \mu\text{T}; on the axis at z=5 cmz = 5\ \text{cm} it falls by (1/2)3(1/\sqrt{2})^3 to 222 μT222\ \mu\text{T}.

Simulation. Use biot_savart with 50 turns as one loop of 50 A50\ \text{A}, or as a short helix, and print BzB_z every 1 cm1\ \text{cm} along the axis.

What you would measure. Wind the coil on a cardboard former with enamelled wire of about 0.5 mm0.5\ \text{mm} (its resistance is about 1.4 Ω1.4\ \Omega). Drive it from a bench supply in constant-current mode at 1.0 A1.0\ \text{A} (voltage limit 5 V5\ \text{V}). Measure BzB_z with a ratiometric linear Hall sensor on a 5 V5\ \text{V} supply (typical sensitivities are about 11 to 5 mV5\ \text{mV} per 0.1 mT0.1\ \text{mT}, so expect roughly 6060 to 300 mV300\ \text{mV} of change at the centre; Position, Light and Hall Sensors) or with a phone's magnetometer. Subtract the reading with the current off (the Earth's field and the bench steel), or reverse the current and take half the difference. Expect agreement within 5 to 10 %: the sensor's own calibration, its position (±2 mm\pm 2\ \text{mm} near the coil changes BB by several percent) and the winding's real radius dominate. Plot measured against computed Bz(z)B_z(z).

Hazards and safe setup. Low voltage, current-limited. The coil warms slowly at 1.4 W1.4\ \text{W}; check it by touch after a few minutes. If you switch the current with a switch rather than the supply's output button, put a diode across the coil (cathode to the positive end) to absorb the inductive kick.

Pitfalls

  • Wrong direction of R\mathbf{R}. It points from the source element to the field point; reversing it flips the field.
  • Evaluating on the wire. The thin-wire formula diverges at R=0R = 0; inside a real conductor use the volume form or Ampère's law.
  • Too few segments near the point. A field point close to the wire needs segments shorter than the distance to it.
  • Forgetting the background. The Earth's field (2525 to 65 μT65\ \mu\text{T}) is the size of a 1 A1\ \text{A} loop's field; always subtract a zero-current reading.

Practice

  1. A straight wire 1 m1\ \text{m} long carries 2 A2\ \text{A}. Find HH at 5 cm5\ \text{cm} from its midpoint and compare with the infinite-wire value.
  2. What current in a single circular loop of radius 10 cm10\ \text{cm} gives 50 μT50\ \mu\text{T} at its centre?
  3. A loop's on-axis field is 100 μT100\ \mu\text{T} at the centre. What is it at z=az = a?
Answer
  1. sin⁡α=0.5/0.52+0.052=0.995\sin\alpha = 0.5/\sqrt{0.5^2 + 0.05^2} = 0.995, so H=24π⋅0.05(2⋅0.995)=6.335 A/mH = \frac{2}{4\pi \cdot 0.05}(2 \cdot 0.995) = 6.335\ \text{A/m} (B=7.96 μTB = 7.96\ \mu\text{T}); infinite wire: 6.366 A/m6.366\ \text{A/m}, only 0.5 % more.
  2. I=2aB/μ0=2⋅0.1⋅50×10−6/(4π×10−7)=7.96 AI = 2aB/\mu_0 = 2 \cdot 0.1 \cdot 50 \times 10^{-6}/(4\pi \times 10^{-7}) = 7.96\ \text{A}.
  3. B(a)/B(0)=a3/(2a2)3/2=2−3/2=0.354B(a)/B(0) = a^3/(2a^2)^{3/2} = 2^{-3/2} = 0.354, so 35.4 μT35.4\ \mu\text{T}.

Test yourself

In dH=I dl×R/(4πR3)d\mathbf{H} = I\,d\mathbf{l} \times \mathbf{R}/(4\pi R^3), the vector R\mathbf{R} points…

  1. from the field point to the current element
  2. from the current element to the field point
  3. along the current
  4. radially out of the wire's axis only

The field at the centre of a circular loop of radius aa carrying II is…

  1. I/(2πa)I/(2\pi a)
  2. I/(2a)I/(2a)
  3. I/(4πa2)I/(4\pi a^2)
  4. Ia2/2Ia^2/2

Far from a small current loop along its axis, the field falls off as…

  1. 1/z1/z
  2. 1/z21/z^2
  3. 1/z31/z^3
  4. e−ze^{-z}

A Helmholtz pair spaces two identical coaxial loops by…

  1. one radius
  2. one diameter
  3. half a radius
  4. two diameters