Moving charge produces magnetic field, and a wire carrying current produces magnetic field around it. We determine the magnetic field of a straight wire at a field point. Straight wires are largely used and the expression of magnetic field for such cases is important.

Consider a straight current carrying conductor of length \(2a\) as shown in Figure 1. The wire is perpendicular to the x-axis and the the x-axis bisects the wire. The lower end of the wire is at \(y = -a\) and the upper end at \(y = a\). We determine the magnetic field due to the wire at the field point \(p\) at perpendicular distance \(x\) from the wire.

Figure 1 Magnetic field of a wire.

First we determine the magnetic field due to a length element of the wire \(d\vec l\) at \(y\) using Biot-Savart law and integrate to determine the total magnetic field at the field point. The distance between \(dl\) at \(y\) and the point \(p\) at \(x\) is \(r = \sqrt{x^2 + y^2}\). And the angle between \(d\vec l\) and \(\vec r\) is \(\theta\). Let \(d\vec l\) be \(d\vec y\) in terms of y-coordinate.

From the Figure 1 above, you know \(\sin \theta = \sin(\pi - \theta) = x/r = x / \sqrt{x^2 + y^2}\). Using Biot-Savart law, the magnetic field \(dB\) due to the current element of length \(dl = dy\) is

\[dB = \frac{\mu_0}{4\pi}\frac{I\,dy\sin \theta}{r^2} = \frac{\mu_0}{4\pi}\frac{I\,x\,dy}{(x^2 + y^2)^{3/2}} \]

You can easily determine the direction of magnetic field using right hand rule which in this case is into the screen (away from you). Now the total magnetic field due to the entire current at the field point \(p\) is determined by integrating the above expression from \(y = -a\) to \(y = a\).

\[B = \frac{\mu_0I}{4\pi}\int_{-a}^a\frac{\,x\,dy}{(x^2 + y^2)^{3/2}} \]

Note that electromagnetism is mathematically demanding and you must know the integration! Here the result of the integration is shown, that is

\[B = \frac{\mu_0I}{4\pi}\frac{2a}{\sqrt{x^2 + a^2}}\]

For an infinitely long current-carrying conductor, the value of \(a\) is large enough that we can neglect \(x\) entirely, that is for \(a >> x\), the magnetic field is

\[ B = \frac{\mu_0I}{2\pi\,x}\]

The magnetic field is proportional to the distance from the wire, that is it decreases by increasing the distance from the wire. We determined the electric field of a straight wire of infinite length and determined an expression \(E = \lambda / 2\pi\,\epsilon_0x\) which is similar to the expression of magnetic field just determined. The difference between electric and magnetic fields of straight current carrying conductor is that the electric field is radially outward but the magnetic field surrounds the conductor in circles as illustrated in Biot-Savart law. Furthermore electric field lines start and end at the charges but magnetic field lines always form closed loops never ending at a point.