Magnets are not the only source of magnetic fields. In 1820, Hans Christian Oersted discovered that an electric current flowing through a wire caused a nearby compass to deflect. This indicated that the current in the wire was generating a magnetic field. Oersted studied the nature of the magnetic field around the long straight wire. He found that the magnetic field existed in circular form around the wire and that the intensity of the field was directly proportional to the amount of current carried by the wire. He also found that the strength of the field was strongest next to the wire and diminished with distance from the conductor until it could no longer be detected. In most conductors, the magnetic field exists only as long as the current is flowing (i.e. an electrical charge is in motion). However, in ferromagnetic materials the electric current will cause some or all of the magnetic domains to align and a residual magnetic field will remain.
Oersted also noticed that the direction of the magnetic field was dependent on the direction of the electrical current in the wire. A three-dimensional representation of the magnetic field is shown below. There is a simple rule for remembering the direction of the magnetic field around a conductor. It is called the right-hand clasp rule. If a person grasps a conductor in one's right hand with the thumb pointing in the direction of the current, the fingers will circle the conductor in the direction of the magnetic field.
A word of caution about the right-hand clasp rule
For the right-hand rule to work, one important thing that must be remembered about the direction of current flow. Standard convention has current flowing from the positive terminal to the negative terminal. This convention is credited to Benjamin Franklin who theorized that electric current was due to a positive charge moving from the positive terminal to the negative terminal. However, it was later discovered that it is the movement of the negatively charged electron that is responsible for electrical current. Rather than changing several centuries of theory and equations, Franklin's convention is still used today.