In physics, a magnetic field is an entity produced by moving electric charges (electric currents) that exerts a force on other moving charges. (The quantummechanical spin of a particle produces magnetic fields and is acted on by them as though it were a current; this accounts for the fields produced by "permanent" ferromagnets.)
A magnetic field is a vector field: it associates with every point in space a vector that may vary in time. The direction of the field is the equilibrium direction of a compass needle placed in the field.
Magnetic field is usually denoted by the symbol . Historically, was called the magnetic flux density or the magnetic induction, and was called the magnetic field (or magnetic field strength), and this terminology is still often used to distinguish the two in the context of magnetic materials (nontrivial permeability μ). Otherwise, however, this distinction is often ignored, and both symbols are frequently referred to as the magnetic field. (Some authors call H the auxiliary field, instead.) In SI units, and are measured in teslas (T) and amperes/meter (A/m), respectively; or, in cgs units, in gauss (G) and oersteds (Oe), respectively.
Formal definition
Like the electric field, the magnetic field can be defined by the force it produces. In SI units, this is:
where

F is the force produced, measured in newtons

indicates a vector cross product

is electric charge, measured in coulombs

is velocity, measured in metres per second

B is magnetic flux density, measured in teslas
This law is called the Lorentz force law.
If the moving charge is part of a current in a wire, then an equivalent form of the law is
In words, this equation says that the force per unit length of wire is the cross product of the current vector and the magnetic field. In the equation above, the current vector, , is a vector with magnitude equal to the usual scalar current, i, and direction pointing along the wire that the current is flowing.
The most compact and elegant mathematical statements describing how magnetic fields are produced makes use of vector calculus.
In free space:
where

is the curl operator

is the divergence operator

is permeability

is current density

is the partial derivative

is the freespace permittivity

is the electric field

is time
The first equation is known as Ampère's law with Maxwell's correction. The second term of this equation (Maxwell's correction) disappears in static or quasistatic systems. The second equation is a statement of the observed nonexistence of magnetic monopoles. These are two of Maxwell's equations.
Properties
Maxwell did much to unify static electricity and magnetism, producing a set of four equations relating the two fields. However, under Maxwell's formulation, there were still two distinct fields describing different phenomena. It was Albert Einstein who showed, using special relativity, that electric and magnetic fields are two aspects of the same thing (a rank2 tensor), and that one observer may perceive a magnetic force where a moving observer perceives only an electrostatic force. Thus, using special relativity, magnetic forces are a manifestation of electrostatic forces of charges in motion and may be predicted from knowledge of the electrostatic forces and the movement (relative to some observer) of the charges.
A thought experiment one can do to show this is with two identical infinite and parallel lines of charge having no motion relative to each other but moving together relative to an observer. Another observer is moving alongside the two lines of charge (at the same velocity) and observes only electrostatic repulsive force and acceleration. The first or "stationary" observer seeing the two lines (and second observer) moving past with some known velocity also observes that the "moving" observer's clock is ticking more slowly (due to time dilation) and thus observes the repulsive acceleration of the lines more slowly than that which the "moving" observer sees. The reduction of repulsive acceleration can be thought of an attractive force, in a classical physics context, that reduces the electrostatic repulsive force and also that is increasing with increasing velocity. This pseudoforce is precisely the same as the electromagnetic force in a classical context.
Changing magnetic fields, according to Faraday's law of induction, can induce an electric field and thus an electric current; similar currents can be induced by conductors moving in a fixed magnetic fields. These phenomena are the basis for many electric generators and electric motors.
Magnetic field lines
Magnetic field lines emanate primarily from the north pole of a magnet and curve around to the south pole
Technically, the magnetic field isn't a vector according to the formal definition, it is a pseudovector: it gains an extra sign flip under improper rotations of the coordinate system. (The distinction is important when using symmetry to analyze magneticfield problems.) This is a consequence of the fact that B is related to two true vectors by a cross product (e.g. in the Lorentz force law).
See also