structural:reformatting, information:highlighting, linguistic:paraphrasing
Magnetic field due to moving charges and electric currents

All moving charged particles produce magnetic fields. Moving point charges, such as electrons, produce complicated but well known magnetic fields that depend on the charge, velocity, and acceleration of the particles.

Magnetic field lines form in concentric circles around a cylindrical current-carrying conductor, such as a length of wire. The direction of such a magnetic field can be determined by using the " right-hand grip rule " (see figure at right). The strength of the magnetic field decreases with distance from the wire. (For an infinite length wire the strength is inversely proportional to the distance.)

Bending a current-carrying wire into a loop concentrates the magnetic field inside the loop while weakening it outside. Bending a wire into multiple closely spaced loops to form a coil or " solenoid " enhances this effect. A device so formed around an iron core may act as an electromagnet, generating a strong, well-controlled magnetic field. An infinitely long cylindrical electromagnet has a uniform magnetic field inside, and no magnetic field outside. A finite length electromagnet produces a magnetic field that looks similar to that produced by a uniform permanent magnet, with its strength and polarity determined by the current flowing through the coil.

The magnetic field generated by a steady current I (a constant flow of electric charges, in which charge neither accumulates nor is depleted at any point) is described by the Biot–Savart law: B = μ 0 I 4 π ∫ w i r e d ℓ × r ^ r 2, {\displaystyle \mathbf {B} ={\frac {\mu _{0}I}{4\pi }}\int _{\mathrm {wire} }{\frac {\mathrm {d} {\boldsymbol {\ell }}\times \mathbf {\hat {r}} }{r^{2}}},} where the integral sums over the wire length where vector d ℓ is the vector line element with direction in the same sense as the current I, μ is the magnetic constant, r is the distance between the location of d ℓ and the location where the magnetic field is calculated, and r̂ is a unit vector in the direction of r. For example, in the case of a sufficiently long, straight wire, this becomes: | B | = μ 0 2 π r I {\displaystyle |\mathbf {B} |={\frac {\mu _{0}}{2\pi r}}I} where r = | r |. The direction is tangent to a circle perpendicular to the wire according to the right hand rule.

A slightly more general way of relating the current I {\displaystyle I} to the B -field is through Ampère's law: ∮ B ⋅ d ℓ = μ 0 I e n c, {\displaystyle \oint \mathbf {B} \cdot \mathrm {d} {\boldsymbol {\ell }}=\mu _{0}I_{\mathrm {enc} },} where the line integral is over any arbitrary loop and I enc {\displaystyle I_{\text{enc}}} is the current enclosed by that loop. Ampère's law is always valid for steady currents and can be used to calculate the B -field for certain highly symmetric situations such as an infinite wire or an infinite solenoid.

In a modified form that accounts for time varying electric fields, Ampère's law is one of four Maxwell's equations that describe electricity and magnetism.