What is a magnetic field? What are magnetic field lines?
Magnetic fields are historically described in terms of their effect on electric charges. A moving electric charge, such as an electron, will accelerate in the presence of a magnetic field, causing it to change velocity and its direction of travel. This is, for example, the principle used in televisions, computer monitors, and other devices with CRTs (cathode-ray tubes). In a CRT, electrons are emitted from a hot filament. A voltage difference pulls these electrons from the filament to the picture screen. Electromagnets surrounding the tube cause these electrons to change direction, so they hit different locations on the screen.
This is how it works: An electrically charged particle moving in a magnetic field will experience a force (known as the Lorentz force) pushing it in a direction perpendicular to the magnetic field and the direction of motion:
As a result of this force, the charged particle accelerates in the direction of the force (this is Newton's second law). In the diagram above the particle's trajectory will curve upward.
Magnetic fields are perhaps more easily understood in terms of magnetic field lines. Field lines, also known as lines of force, define the direction and strength of the magnetic field at any local in space. As explained later, magnetic fields have both a direction and strength (or "magnitude"). The direction of the field lines indicates the direction of the field, while the density of the field lines indicates the magnitude of the field. Thus at points where the field lines are closer together, the field is stronger. Field lines are described mathematically with a quantity known as flux.
Magnetic fields are commonly a result of magnetic dipoles. A simple example of a magnetic dipole is the bar magnet:
As you can see, the magnetic field lines always begin on the north pole of a magnet, and end on the south pole. This diagram illustrates the magnetic field lines of a typical magnetic dipole.
Magnetic dipoles always like to align themselves parallel to an external magnetic field, so the dipole's field matches the one applied to it. This is why bar magnets line up north-to-south. It also explains the behavior of a compass needle, which, being composed of Iron (a ferromagnet), behaves like a magnetic dipole.