The Core Magnetic Field Calculation Formulas
The magnetic field calculation for a long solenoid (electromagnet) is defined by B = μ₀ · μᵣ · (N / L) · I. For a long straight wire, the calculation is B = (μ₀ · I) / (2π · r). These two equations govern 95% of practical magnetic design in DIY electronics, relay selection, and PCB layout.
| Symbol | Parameter | SI Unit | Typical Value / Notes |
|---|---|---|---|
| B | Magnetic Flux Density | Tesla (T) | Often measured in mT or μT in practice. |
| μ₀ | Vacuum Permeability | H/m or T·m/A | ≈ 4π × 10⁻⁷ (1.2566 × 10⁻⁶) NIST CODATA. |
| μᵣ | Relative Permeability | Dimensionless | Air = 1; Iron = 200 to 5000. |
| N | Number of Turns | Count | Total wire wraps in the coil. |
| L | Coil Length | Meters (m) | Length of the wound section, not the wire. |
| I | Current | Amperes (A) | DC current or RMS AC current. |
| r | Radial Distance | Meters (m) | Distance from the center of the wire. |
Boundary Conditions, Realistic Magnitudes, and Unit Traps
Before plugging numbers into the magnetic field calculation, you must verify your physical assumptions and unit scales. Using these formulas outside their boundary conditions yields mathematically correct but physically useless results.
When the Formulas Apply (and When They Fail)
- Solenoid Formula (B = μ₀ · μᵣ · (N / L) · I): Assumes an "infinitely long" solenoid where L ≫ diameter. If your coil is short and fat (L is less than 3× the diameter), the field at the center will be roughly 50% to 70% of the calculated value due to fringing. For short coils, you must use the Biot-Savart elliptic integral derivations (HyperPhysics).
- Straight Wire Formula (B = (μ₀ · I) / (2π · r)): Assumes the wire length is much greater than r. If you are calculating the field near the end of a trace or a short jumper wire, the actual field will be lower.
Realistic Answer Magnitudes
If your calculation yields 50 T for a DIY coil, you have made a math error. Use this sanity-check scale:
- Earth's Magnetic Field: ~50 μT (0.00005 T)
- PCB Trace Interference: 10 μT to 100 μT
- Air-Core Solenoid (DIY): 1 mT to 10 mT (0.001 to 0.01 T)
- Iron-Core Solenoid / Relay: 0.1 T to 1.2 T
- Saturation Limit of Soft Iron: ~1.5 T to 2.0 T (Adding more current beyond this point yields almost zero increase in B).
- Neodymium Permanent Magnet (N52): ~1.4 T at the surface.
1. The Centimeter Trap: Using centimeters for L or r without converting to meters. This throws your answer off by exactly 100×.
2. The Permeability Confusion: Multiplying by the relative permeability (μᵣ = 2000 for iron) but forgetting to multiply by vacuum permeability (μ₀). μᵣ is just a multiplier; it has no units on its own.
Rearranged Forms for Component Selection
In bench practice, you rarely know B and need to find it. Usually, you have a target B and need to size the power supply or wind the coil. Here are the algebraically rearranged forms for the solenoid equation:
- Solve for Current (I):
I = (B · L) / (μ₀ · μᵣ · N)— Use this to size your MOSFET or relay driver. - Solve for Turns (N):
N = (B · L) / (μ₀ · μᵣ · I)— Use this to determine how much magnet wire to buy. - Solve for Length (L):
L = (μ₀ · μᵣ · N · I) / B— Use this to size the bobbin or core. - Solve for Distance (r) [Straight Wire]:
r = (μ₀ · I) / (2π · B)— Use this to set keep-out zones on PCBs for sensitive Hall-effect sensors.
Worked Examples with Strict Unit Tracking
Below are two solved problems demonstrating strict unit tracking to prevent order-of-magnitude errors.
Problem 1: PCB Trace Interference (Straight Wire)
Scenario: You have a 5A motor drive trace on a PCB. A Hall-effect current sensor is placed 10 mm away from the trace. What is the parasitic magnetic field (B) hitting the sensor? Assume air core (μᵣ = 1).
- Identify Formula: B = (μ₀ · I) / (2π · r)
- Convert Units: I = 5 A; r = 10 mm = 0.01 m; μ₀ = 4π × 10⁻⁷ T·m/A.
- Substitute: B = (4π × 10⁻⁷ T·m/A · 5 A) / (2π · 0.01 m)
- Cancel π and Amps: B = (20 × 10⁻⁷ T·m) / (0.02 m)
- Calculate: B = 1000 × 10⁻⁷ T = 100 × 10⁻⁶ T
- Final Answer: B = 100 μT. (This is twice the Earth's magnetic field and will cause significant offset error in an uncalibrated Hall sensor).
Problem 2: DIY Magnetic Lock (Solenoid)
Scenario: You are winding a solenoid around a 1018 low-carbon steel core to build a 12V magnetic lock. You need a flux density of B = 0.8 T to generate sufficient holding force. The core length (L) is 5 cm. The steel has a relative permeability (μᵣ) of 1,000. How many Ampere-turns (N · I) do you need?
- Identify Formula: B = μ₀ · μᵣ · (N · I) / L
- Rearrange for N·I: N · I = (B · L) / (μ₀ · μᵣ)
- Convert Units: B = 0.8 T; L = 5 cm = 0.05 m; μᵣ = 1000.
- Substitute: N · I = (0.8 T · 0.05 m) / (4π × 10⁻⁷ T·m/A · 1000)
- Simplify Denominator: 4π × 10⁻⁴ ≈ 1.2566 × 10⁻³ T·m/A
- Calculate Numerator: 0.8 · 0.05 = 0.04 T·m
- Divide: N · I = 0.04 / 0.0012566 = 31.83 A
- Final Answer: You need 31.8 Ampere-turns. If your 12V supply pushes 1A through the coil, you need exactly 32 turns of wire.
Decision Path: Sizing an Electromagnet Coil
Use this decision matrix to terminate your design process with a concrete wire gauge, core material, and power supply selection. Do not guess; follow the target flux density.
| Target B Field | Core Material (μᵣ) | Wire Gauge & Voltage | Application & Concrete Pick |
|---|---|---|---|
| < 5 mT | Air / Plastic (1) | 26 AWG, 5V to 12V | RFID Antennas, Metal Detectors. Pick: 26 AWG enameled copper, 100 turns, 12V DC. |
| 5 mT to 0.5 T | Ferrite (200 - 2000) | 24 AWG, 12V to 24V | Relays, Solenoid Valves. Pick: 24 AWG polyurethane-coated wire, 500 turns on an E-core ferrite bobbin, 12V supply (approx 40Ω coil). |
| 0.5 T to 1.2 T | Soft Iron / 1018 Steel (1000 - 4000) | 20 AWG to 18 AWG, 24V+ | Magnetic Locks, Scrapyard Lifters. Pick: 20 AWG magnet wire, 200 turns on a solid 1018 steel cylinder, driven by a 24V 3A constant-voltage supply. |
| > 1.5 T | N/A (Iron Saturates) | N/A | Stop Designing. Soft iron physically saturates near 1.5T. Adding more wire/current only generates heat. Default Pick: Switch to an N52 Neodymium permanent magnet for the baseline field, and use a small coil only to modulate/switch it. |
If you are building a custom 12V linear actuator or locking solenoid and lack precise FEA simulation software, default to 24 AWG magnet wire wrapped around a 1018 low-carbon steel core. Wind approximately 500 turns over a 2 cm length. This yields a coil resistance of roughly 40Ω, drawing 300mA from a 12V supply (3.6W). It will generate approximately 0.2 T to 0.3 T of flux density—enough to pull a steel armature with 5 to 10 lbs of force without melting the wire insulation or requiring a massive heatsink.






