Ampere Law Simulator Back
Electromagnetism Simulator

Ampere Law Simulator — Magnetic Field of Straight Currents and Solenoids

Real-time computation of the field around an infinite straight wire $B = \mu_0 I/(2\pi r)$, the uniform interior field of a solenoid $B = \mu_0 n I$, and the force per length between parallel currents, all from Ampere's law. Visualized side by side with circular field lines, a solenoid cross-section and a log-log plot.

Parameters
Current I
A
Distance from wire r
cm
Solenoid winding density n
/cm
Parallel wire spacing d
cm

Vacuum permeability mu0 = 4 pi * 10^-7 T m/A. The straight wire produces concentric circular field lines (right-hand rule); the solenoid is uniform along its axis inside.

Results
Straight wire B (at r)
Solenoid interior B
Force per length F/L (parallel)
B_sol / B_wire
Wire field lines and solenoid cross-section

Left: a straight wire (red dot = current out of page) with concentric circular field lines; yellow dashed circle = observation radius r; orange arrow = B direction. Right: solenoid cross-section (blue dots/crosses = winding turns; orange arrows inside = uniform field B = mu0 n I; outside is essentially zero).

Straight wire B(r) profile (log-log)

x = distance r [cm] from 0.1 to 100 (log10); y = magnetic flux density B [T] (log10); blue line = B(r) = mu0 I / (2 pi r) (slope -1); yellow dot = current (r, B_wire); orange dashed line = solenoid reference B = mu0 n I.

Theory & Key Formulas

Ampere's law states that the line integral of $\boldsymbol{B}$ around a closed loop $C$ is proportional to the enclosed current:

$$\oint_C \boldsymbol{B} \cdot d\boldsymbol{\ell} = \mu_0\,I_{\mathrm{enc}}$$

Magnetic flux density of an infinite straight wire (current $I$) at distance $r$:

$$B_{\mathrm{wire}}(r) = \frac{\mu_0\,I}{2\pi\,r}$$

Interior field of an infinite solenoid (turns per unit length $n$):

$$B_{\mathrm{sol}} = \mu_0\,n\,I$$

Force per unit length between parallel currents (current $I$, spacing $d$):

$$\frac{F}{L} = \frac{\mu_0\,I^2}{2\pi\,d}$$

$\mu_0 = 4\pi \times 10^{-7}$ T m/A is the vacuum permeability, $I$ the current [A], $r$ the distance from the wire centre [m], $n$ turns per unit length [turns/m], $d$ the spacing between parallel wires [m].

What is the Ampere Law Simulator?

🙋
My textbook writes Ampere's law as $\oint \boldsymbol{B} \cdot d\boldsymbol{\ell} = \mu_0 I_{\mathrm{enc}}$. Why bother with the contour integral when the Biot-Savart law already gives B?
🎓
For symmetric problems Ampere's law is dramatically faster. Take an infinite straight wire: by symmetry B is constant on every circle around the wire. Pick a circle of radius r as your Amperian loop and the integral collapses to $B \cdot 2\pi r = \mu_0 I$, giving $B = \mu_0 I/(2\pi r)$ instantly. Biot-Savart would have you integrate over the whole length. The left canvas in this simulator is exactly that picture: concentric field lines.
🙋
At the defaults (I=10A, r=5cm) B is 40 microtesla — that's basically the geomagnetic field. Surprisingly weak, isn't it?
🎓
Yes, geomagnetic field is roughly 30 to 60 microtesla, so we're in the same league. 10 A is a fairly strong current (a hairdryer level), yet 5 cm away the field is already at geomagnetic levels and falls as 1/r — at 1 m it's 2 microtesla, at 10 m it's 0.2 microtesla. This is why ordinary house wiring causes no measurable magnetic exposure. Now look at the solenoid: at the same I=10A but n=100 turns/cm the interior is 126 millitesla, more than 3000 times the geomagnetic field. Try the slider!
🙋
The solenoid formula $B = \mu_0 n I$ has no radius and no length. Does that really mean a fat solenoid and a thin one give the same interior field?
🎓
Yes, in the infinite-length limit the field is uniform inside and independent of position and radius. The reason is that the rectangular Amperian loop has $B \cdot L = \mu_0 (n L) I$, and L cancels. In real solenoids end effects creep in if length/diameter is below ten or so: drop of a few percent at center, halved at the very ends. MRI bores are extremely long and thin precisely to push the end effects out of the imaging volume.
🙋
I never noticed parallel currents pulling on each other. Is there a real-world setting where it actually matters?
🎓
For household wiring (default 0.20 mN/m) you'd never feel it. But during a lightning strike with tens of kA on two parallel paths in the air, $F/L \propto I^2$ produces explosive attraction. In substations bus bars carrying tens of kA during a short circuit must be mechanically braced or they fly off — utility engineers call this the "short-circuit electromechanical force" design item. Set I to 100 A and d to 1 mm in this tool and F/L jumps to roughly 2 N/m.

Frequently Asked Questions

The divergence at r = 0 is a mathematical artefact of treating the wire as an infinitely thin line. Real wires have finite radius a; assuming uniform current density inside, the interior field is B = mu0 I r / (2 pi a^2), which grows linearly with r, peaks at the surface r = a as B = mu0 I / (2 pi a), and matches the 1/r law beyond that. This simulator restricts r to at least 0.1 cm, well outside typical millimetre-scale wiring, so the external 1/r form applies.
Ampere's law is dramatically simpler for problems with high symmetry: infinite straight wires, infinite solenoids, toroids, infinite current sheets — all of these collapse to a one-line answer. For asymmetric geometries (finite-length coils, off-axis points of a circular loop, complex 3D wiring) Ampere's law still holds but cannot be inverted to give B; you must integrate Biot-Savart numerically. The rule of thumb is "find the symmetry, use Ampere; otherwise, integrate Biot-Savart". Our circular loop tool sits on the Biot-Savart side; this tool sits on the Ampere side.
Replace mu0 with mu = mu_r mu0 in B = mu0 n I and you get the iron-core estimate. Soft iron has mu_r in the 5,000 to 10,000 range, silicon steel up to 40,000, so the interior field is enhanced by orders of magnitude. That is why relays, transformers and solenoid valves all have iron cores. The catch is saturation: above B_sat (typically 1.5 to 2.2 T) mu_r drops sharply, so very high field applications (MRI, accelerator magnets) switch to superconducting wire with an air core. This tool covers the air-core case.
In 1865 Maxwell added a correction so that the law reads ∮ B · dℓ = mu0 (I_enc + epsilon0 d Phi_E / dt). The second term, the displacement current, says that a time-varying electric field also generates a magnetic field. This correction predicted electromagnetic waves (light, radio). For DC and quasistatic situations it is negligible, but for capacitor charging, RF circuits and antennas it must be included. This simulator handles only steady currents.

Real-World Applications

MRI main magnets: the 1.5 T to 7 T fields in clinical MRI scanners come from superconducting solenoids. Inverting $B = \mu_0 n I$ to make 3 T requires nI ≈ 2.4 × 10^6 A·turns/m — for example 1000 turns/cm at 24 A, or 100 turns/cm at 240 A. In practice superconducting wire carries 100 A class current at 1000 turns/cm, run in persistent-current mode for years of stable field.

Electromagnets (relays and solenoid valves): car starters, washing-machine inlet valves, factory pneumatic valves all rely on "current → solenoid field → iron armature pulled in", a direct application of Ampere's law. The default settings in this tool give 126 mT for the air-core case; an iron core (mu_r ≈ 5000) would naively multiply this by 5000, but in reality saturates at 1.5 to 2 T and produces an attractive force F ∝ B^2 A / (2 mu0).

Power-line magnetic fields and human exposure: overhead lines (22 kV to 500 kV) carry 100 to 2000 A and hang 10 to 30 m above ground. Plug I=1000 A and r=10 m into this tool and you get B ≈ 20 microtesla, half the geomagnetic field. The WHO long-term-exposure guideline (100 microtesla) is comfortably above that, which is the scientific basis for "magnetic exposure under power lines is not a concern". Domestic wiring (10 A at 50 cm) sits around 4 microtesla.

Railguns and electromagnetic launchers: two parallel rails carry huge current to accelerate a sliding armature; the parallel-current force is the propulsion. The U.S. Navy prototype runs about 5 MA with mega-newton forces, accelerating plasma slugs to 7 km/s. Setting I=100 A and d=1 cm here gives F/L = 0.2 N/m, letting you intuit how a 50,000-fold increase in I scales F/L by 2.5 billion.

Common Misunderstandings

The most frequent misconception is to think "the solenoid field is only on the centre axis". In an ideal infinite solenoid the field is B = mu0 n I everywhere inside (centre, off-axis points, except very near the ends). This is fundamentally different from a circular loop, where B(z) is defined only on the axis, and is the main reason solenoids are chosen as the main field source for MRI and electromagnets. The multiple orange arrows on the right canvas indicate this uniformity.

Next is assuming "there is only one Amperian loop you can choose". Ampere's law $\oint B \cdot d\ell = \mu_0 I_{\mathrm{enc}}$ holds for any closed curve, but to extract B alone you must pick a curve that matches the symmetry: concentric circles for a straight wire, rectangles for a solenoid, circles for a toroid. For asymmetric problems (finite solenoids etc.) Ampere's law still holds but cannot be solved in one line for B, so numerical Biot-Savart integration is needed.

Finally, do not jump to "the parallel-wire force diverges at d = 0 and is therefore dangerous". The formula F/L = mu0 I^2 / (2 pi d) treats the wires as infinitely thin lines; real wires of diameter a have centre-to-centre distance d while their surfaces meet at d − a, so they touch physically before the formula diverges. In power engineering the practical concern is the short-circuit electromechanical force computed at d ≈ a few mm to a few cm and I ≈ tens of kA — the natural extrapolation of the scale this tool covers (d ≥ 1 mm, I ≤ 100 A).