\(\)
Ampère’s law relates the magnetic field of a closed loop to the electric current passing through that loop.
Ampère’s law
A current going into the paper, causes a magnetic field at distance \(r\) tangentially to the circle
$$ B = \frac{\mu_0 I}{2 \pi r} \nonumber $$
Now, carve the circle up in little elements \(d\vec l\),
The closed circle integral, with \(\newcommand{\parallelsum}{\mathbin{\!/\mkern5mu/\!}} \vec B \parallelsum d\vec l\) $$ \begin{align*} \oint \vec B \cdot d\vec l &= B\oint dl, & \left(\oint dl=2\pi r\right) \\ &= B\, 2\pi r, & \left(B = \frac{\mu_0 I}{2 \pi r}\right) \\ &= \frac{\mu_0 I}{\bcancel{2 \pi r}}\, \bcancel{2\pi r} \\ &= \mu_0I \end{align*} $$
Note:
 Note the different \(d\vec l\). One is along the wire, other other around the circle.
 It doesn’t matter what distance \(r\), the integral is always \(\mu_0 I\)
Ampère first realized that you could walk around in any closed crooked path,
Enclosed current definition
In the formula above, \(I_\rm{encl}\) stands for enclosed current. We define this as:
If we have a very strange looking closed path. To that closed loop, we have to attach an open surface. We’re free to choose it. It can be flat, or e.g. like a bakers hat.
If the current goes in the curve and penetrates the surface, the current is said to be enclosed.
By convention, we applying righthand corkscrew notation for the connection between the magnetic field and current.
 If we follow current \(I_1\), the direction is clockwise and \(I_1\gt 0\) and \(I_2\lt 0\)
 If we follow current \(I_2\), the direction is counter clockwise and \(I_1\lt 0\) and \(I_2\gt 0\)
Since you are free to choose a surface attached to the loop, if you can get away with it, you can use a flat surface.
Now we can calculate the magnetic field inside a wire that draws a current using Ampère’s Law.
Straight wire
Let’s assume an uniform current throughout the wire. What is the magnetic field everywhere?

For \(r \gt R\):
Because of the cylindrical symmetry, we choose a circle as the path. So the magnetic field strength is the same everywhere.

For \(r \lt R\): again, because of the cylindrical symmetry, we choose a circle as the path. So the magnetic field strength is the same everywhere.
If you substitute \(r=R\), for the magnetic field right at the surface, you find exactly the same result as for the case where \(r\gt R\).
Plotting \(B(r)\)
Solenoids
A solenoid is a cylindrical coil of wire that acts as a magnet.
Remember, the circular current loop.
Looking at its cross section and its magnetic field configuration
If you now add other loops next to it, these loops also pull the field lines “to come through” its circle. So you’re beginning to get a nearconstant magnetic field. The more tightly these loops are wound, the more constant the magnetic field will be.
Magnetic field inside
A solenoid with length \(L\), radius \(R\), current \(I\), there are \(N\) windings and looking from the left the windings are clockwise. We assume the field outside the solenoid is approximate zero. What is the magnetic field inside the solenoid?
We as a (surprising) path: a rectangle with length \(l\).
In applying Ampère’s law, we split the path in four pieces.
 Path 1: we assumed the magnetic field is zero, so \(\int\vec B\cdot d\vec l=0\)
 Path 2,3: \(\vec B \perp d\vec l\), so the dotproduct is zero
 Path 4: is the only path that contributes to the closedloop integral. Here we assumed \(B\) is constant, and \(\newcommand{\parallelsum}{\mathbin{\!/\mkern5mu/\!}} \vec B \parallelsum d\vec l\). $$ \int \vec B\cdot d\vec l = B \int dl = B\,l \nonumber $$ Now, we attach a flat surface to the closedloop, and calculates the current that penetrates that surface. The number of windings that poke through the surface is $$ B\,\bcancel{l} = \mu_0\,\frac{\bcancel{l}}{L}N\, I \nonumber $$
For as long as \(L \gg R\) $$ \shaded{ B = \frac{\mu_0 I N}{L} } \tag{inside solenoid} $$
Note: that the magnetic field is not proportional to the number of loops, but to the number of loops per unit length. The shape of the magnetic field of one loop is like a dipole field, and spreads. it falls off so rapidly that the other end of the solenoid doesn’t notice it. It matters how close together the windings are, so the windings per unit length.