Magnetic field
In physics, a magnetic field is a field that permeates space and which exerts a magnetic force on moving electric charges and magnetic dipoles. Magnetic fields surround electric currents, magnetic dipoles, and changing electric fields.
When placed in a magnetic field, magnetic dipoles tend to align their axes to be parallel with the magnetic field, as can be seen when iron filings are in the presence of a magnet (see picture at right). Magnetic fields also have their own energy, with an energy density proportional to the square of the field intensity. The magnetic field is typically measured in either teslas (SI units) or gauss (cgs units).
There are some notable specific incarnations of the magnetic field. For the physics of magnetic materials, see magnetism and magnet, and more specifically ferromagnetism, paramagnetism, and diamagnetism. For constant magnetic fields, such as are generated by stationary dipoles and steady currents, see magnetostatics. For magnetic fields created by changing electric fields, see electromagnetism.
The electric field and the magnetic field are tightly interlinked, in two senses. First, changes in either of these fields can cause ("induce") changes in the other, according to Maxwell's equations. Second according to Einstein's theory of special relativity, a magnetic force in one inertial frame of reference may be an electric force in another, or vice-versa  (see relativistic electromagnetism for examples). Together, these two fields make up the electromagnetic field, which is best known for underlying light and other electromagnetic waves.

# Definition
In classical physics, the magnetic field \mathbf{B} is a vector field (that is, some vector at every point of space and time), with SI units of teslas (one tesla is one newton-second per coulomb-metre) and cgs units of gauss. It has the property of being a solenoidal vector field.
The field \mathbf{B} can be both defined and measured by means of a small magnetic dipole (i.e., bar magnet). The magnetic field exerts a torque on magnetic dipoles that tends to make them point in the same direction as the magnetic field (as in a compass), and moreover the magnitude of that torque is proportional to the magnitude of the magnetic field. Therefore, in order to measure the magnetic field at a particular point in space, you can put a small freely-rotating bar magnet (such as a compass) there: the direction it winds up pointing is the direction of \mathbf{B}; and the ratio of the maximum magnitude of the torque to the dipole moment of the bar magnet is the magnitude |\mathbf{B}|.
(There are, in addition, several other different but physically equivalent ways to define the magnetic field, for example via the Lorentz force law (see below), or as the solution to Maxwell's equations.)
It follows from any of these definitions that the magnetic field vector (being a vector product) is a pseudovector (also called an axial vector).
In a bar magnet, for example, the direction of the magnetic field is as follows: In the interior of the magnet, it points roughly towards the magnet's north pole; and outside the magnet, it points roughly towards the magnet's south pole.

## B and H
There are two quantities that physicists may refer to as the magnetic field, notated \mathbf{H} and \mathbf{B}. The vector field \mathbf{H}
is known among electrical engineers as the magnetic field intensity or magnetic field strength also known as auxiliary magnetic field or magnetizing field. The vector field \mathbf{B} is known as magnetic flux density or magnetic induction or simply magnetic field, as used by physicists, and has the SI units of teslas (T), equivalent to webers (Wb) per square metre or volt seconds per square metre. Magnetic flux has the SI units of webers so the \mathbf{B} field is that of its areal density. The vector field \mathbf{H} is measured in Amperes/meter (SI units) or oersted (cgs units) and is something of the magnetic analog to the electric displacement field represented by \mathbf{D}, with the SI units of the latter being ampere-seconds per square metre. Although the term "magnetic field" was historically reserved for \mathbf{H}, with \mathbf{B} being termed the "magnetic induction", \mathbf{B} is now understood to be the more fundamental entity, and most modern writers refer to \mathbf{B} as the magnetic field, except when context fails to make it clear whether the quantity being discussed is \mathbf{H} or \mathbf{B}. See: 
The difference between the \mathbf{B} and the \mathbf{H} vectors can be traced back to Maxwell's 1855 paper entitled On Faraday's Lines of Force. It is later clarified in his concept of a sea of molecular vortices that appears in his 1861 paper On Physical Lines of Force - 1861. Within that context, \mathbf{H} represented pure vorticity (spin), whereas \mathbf{B} was a weighted vorticity that was weighted for the density of the vortex sea. Maxwell considered magnetic permeability  to be a measure of the density of the vortex sea. Hence the relationship,
(1) Magnetic induction current causes a magnetic current density
\mathbf{B} = \mu \mathbf{H}
was essentially a rotational analogy to the linear electric current relationship,
(2) Electric convection current
\mathbf{J} = \rho \mathbf{v}
where \rho is electric charge density. \mathbf{B} was seen as a kind of magnetic current of vortices aligned in their axial planes, with \mathbf{H} being the circumferential velocity of the vortices. With  representing vortex density, we can now see how the product of  with vorticity \mathbf{H} leads to the term magnetic flux density which we denote as \mathbf{B}.
The electric current equation can be viewed as a convective current of electric charge that involves linear motion. By analogy, the magnetic equation is an inductive current involving spin. There is no linear motion in the inductive current along the direction of the \mathbf{B} vector. The magnetic inductive current represents lines of force. In particular, it represents lines of inverse square law force.
The extension of the above considerations confirms that where \mathbf{B} is to \mathbf{H}, and where \mathbf{J} is to , then it necessarily follows from Gauss's law and from the equation of continuity of charge that \mathbf{E} is to \mathbf{D}. ie. \mathbf{B} parallels with \mathbf{E}, whereas \mathbf{H} parallels with \mathbf{D}.
In SI units,  \mathbf{B} \  and  \mathbf{H} \  are measured in teslas (T) and amperes per metre (A/m), respectively; or, in cgs units, in gauss (G) and oersteds (Oe), respectively. Two parallel wires carrying an electric current in the same direction will generate a magnetic field that will cause a force of attraction between them. This fact is used to define the value of an ampere of electric current. See Ampere's force law and ampere.
The fields \mathbf{B} and \mathbf{H} are also related by the equation
where \mathbf{M} is magnetization.

# Force due to a magnetic field

## Force on a charged particle
where

## Force on current-carrying wire
A straight, stationary wire carrying an electric current, when placed in an external magnetic field, feels a force. This force is the result of the Lorentz force (see above) acting on each electron (or any other charge carrier) moving in the wire. The formula for the total force is as follows:
where
Alternatively, some authors write
where the vector direction is now associated with the current variable, instead of the length variable. The two forms are equivalent.
If the wire is not straight but curved, the force on it can be computed by applying this formula to each infinitesimal segment of wire, then adding up all these forces via integration.
The Lorentz force on a macroscopic current is often referred to as the Laplace force.

## Direction of force
The direction of force is determined by the above equations, in particular using the right-hand rule to evaluate the cross product. Equivalently, one can use Fleming's left hand rule for motion, current and polarity to determine the direction of any one of those from the other two, as seen in the example. It can also be remembered in the following way. The digits from the thumb to second finger indicate 'Force', 'B-field', and 'I(Current)' respectively, or F-B-I in short. Another similar trick is the right hand grip rule.

# Magnetic field of a steady current
The magnetic field generated by a steady current (a continual flow of charges, for example through a wire, which is constant in time and in which charge is neither building up nor depleting at any point), is described by the Biot-Savart law:
(in SI units), where
Deriving from the equation, the magnetic field of an infinitely long wire acting to the point at which the field is being computed is then:
This is a consequence of Ampere's law, one of the four Maxwell's equations. Alternatively, it can be thought of as a true, empirical law in its own right, which contributes to the derivation of Maxwell's equations. From a practical point of view, though, the law is true and useful regardless of its philosophical origin.

# Properties

## Magnetic field lines
Like any vector field, the magnetic field can be depicted with field lines -- a set of lines through space whose direction at any point is the direction of the local magnetic field vector, and whose density is proportional to the magnitude of the local magnetic field vector. Note that the choice of which field lines to draw in such a depiction is arbitrary, apart from the requirement that they be spaced out so that their density approximates the magnitude of the local field. The level of detail at which the magnetic field is depicted can be increased by increasing the number of lines.
Although any vector field can be depicted with field lines, this visualization is particularly helpful for the magnetic field (in three-dimensional space), as it makes certain aspects of it more transparent. For example, Gauss's law for magnetism states that the magnetic field is solenoidal (has zero divergence). This is equivalent to the simple statement that, in any field-line depiction of a magnetic field, the field lines cannot have starting or ending points; they must form a closed loop, or else extend to infinity on both ends.
Various physical phenomena have the effect of displaying field lines. For example, iron filings placed in a magnetic field will line up in such a way as to visually show magnetic field lines (see figure at top); although a close inspection will reveal that the "lines" are not quite continuous. Another place where magnetic field lines are visually displayed is in the polar auroras, in which visible streaks of light line up with the local direction of Earth's magnetic field (due to plasma particle dipole interactions).
Note that when a magnetic field is depicted with field lines, it is not meant to imply that the field is only nonzero along the drawn-in field lines. The field is typically smooth and continuous everywhere, and can be estimated at any point (whether on a field line or not) by looking at the direction and density of the field lines nearby. The use of iron filings to display a field presents something of an exception to this picture: the magnetic field is in fact much larger along the "lines" of iron, due to the large permeability of iron relative to air.
The direction of the magnetic field corresponds to the direction that a magnetic dipole (such as a small magnet) will orient itself in that magnetic field (see definition above). Therefore, a cluster of small particles of ferromagnetic material, such as iron filings, placed in the magnetic field will line up in such a way as to visually show the magnetic field lines (see figure at top). Another place where magnetic field lines are visually displayed is the polar auroras, in which visible streaks of light line up with the local direction of Earth's magnetic field.

## Pole labelling confusions
See also North Magnetic Pole and South Magnetic Pole.
The end of a compass needle that points north was historically called the "north" magnetic pole of the needle. Since dipoles are vectors and align "head to tail" with each other to minimize their magnetic potential energy, the magnetic pole located near the geographic North Pole is actually the "south" pole.
The "north" and "south" poles of a magnet or a magnetic dipole are labelled similarly to north and south poles of a compass needle. Near the north pole of a bar or a cylinder magnet, the magnetic field vector is directed out of the magnet; near the south pole, into the magnet. This magnetic field continues inside the magnet (so there are no actual "poles" anywhere inside or outside of a magnet where the field stops or starts). Breaking a magnet in half does not separate the poles but produces two magnets with two poles each.
Earth's magnetic field is probably produced by electric currents in its liquid core.

# Rotating magnetic fields
The rotating magnetic field is a key principle in the operation of alternating-current motors. A permanent magnet in such a field will rotate so as to maintain its alignment with the external field. This effect was conceptualized by Nikola Tesla, and later utilised in his, and others', early AC (alternating-current) electric motors. A rotating magnetic field can be constructed using two orthogonal coils with 90 degrees phase difference in their AC currents. However, in practice such a system would be supplied through a three-wire arrangement with unequal currents. This inequality would cause serious problems in standardization of the conductor size and so, in order to overcome it, three-phase systems are used where the three currents are equal in magnitude and have 120 degrees phase difference. Three similar coils having mutual geometrical angles of 120 degrees will create the rotating magnetic field in this case. The ability of the three-phase system to create a rotating field, utilized in electric motors, is one of the main reasons why three-phase systems dominate the world's electrical power supply systems.
Because magnets degrade with time, synchronous motors and induction motors use short-circuited rotors (instead of a magnet) following the rotating magnetic field of a multicoiled stator. The short-circuited turns of the rotor develop eddy currents in the rotating field of the stator, and these currents in turn move the rotor by the Lorentz force.
In 1882, Nikola Tesla identified the concept of the rotating magnetic field. In 1885, Galileo Ferraris independently researched the concept. In 1888, Tesla gained U.S. Patent 381,968 for his work. Also in 1888, Ferraris published his research in a paper to the Royal Academy of Sciences in Turin.

# Hall effect
Because the Lorentz force is charge-sign-dependent (see above), it results in charge separation when a conductor with current is placed in a transverse magnetic field, with a buildup of opposite charges on two opposite sides of conductor in the direction normal to the magnetic field, and the potential difference between these sides can be measured.
The Hall effect is often used to measure the magnitude of a magnetic field as well as to find the sign of the dominant charge carriers in semiconductors (negative electrons or positive holes).

# Special relativity and electromagnetism
According to special relativity, electric and magnetic forces are part of a single physical phenomenon, electromagnetism; an electric force perceived by one observer will be perceived by another observer in a different frame of reference as a mixture of electric and magnetic forces.  A magnetic force can be considered as simply the relativistic part of an electric force when the latter is seen by a moving observer.
More specifically, rather than treating the electric and magnetic fields as separate fields, special relativity shows that they naturally mix together into a rank-2 tensor, called the electromagnetic tensor. This is analogous to the way that special relativity "mixes" space and time into spacetime, and mass, momentum and energy into four-momentum.

# Magnetic field shape descriptions
- An azimuthal magnetic field is one that runs east-west.
- A meridional magnetic field is one that runs north-south. In the solar dynamo model of the Sun, differential rotation of the solar plasma causes the meridional magnetic field to stretch into an azimuthal magnetic field, a process called the omega-effect. The reverse process is called the alpha-effect.
- A dipole magnetic field is one seen around a bar magnet or around a particle with nonzero spin.
- A quadrupole magnetic field is one seen, for example, between the poles of four bar magnets. The field strength grows linearly with the radial distance from its longitudinal axis.
- A solenoidal magnetic field is similar to a dipole magnetic field, except that a solid bar magnet is replaced by a hollow electromagnetic coil magnet.
- A toroidal magnetic field occurs in a doughnut-shaped coil, the electric current spiraling around the tube-like surface, and is found, for example, in a tokamak.
- A poloidal magnetic field is generated by a current flowing in a ring, and is found, for example, in a tokamak.