An electromagnet is a type of magnet in which the magnetic field is produced by the flow of electric current. The magnetic field disappears when the current is turned off. Electromagnets are widely used as components of other electrical devices, such as motors, generators, relays, loudspeakers, hard disks, MRI machines, scientific instruments, and magnetic separation equipment, as well as being employed as industrial lifting electromagnets for picking up and moving heavy iron objects like scrap iron.
An electric current flowing in a wire creates a magnetic field around the wire (see drawing below). To concentrate the magnetic field, in an electromagnet the wire is wound into a coil with many turns of wire lying side by side. The magnetic field of all the turns of wire passes through the center of the coil, creating a strong magnetic field there. A coil forming the shape of a straight tube (a helix) is called a solenoid; a solenoid that is bent into a donut shape so that the ends meet is called a toroid. Much stronger magnetic fields can be produced if a "core" of ferromagnetic material, such as soft iron, is placed inside the coil. The ferromagnetic core increases the magnetic field to thousands of times the strength of the field of the coil alone, due to the high magnetic permeability μ of the ferromagnetic material. This is called a ferromagnetic-core or iron-core electromagnet.
The direction of the magnetic field through a coil of wire can be found from a form of the right-hand rule. If the fingers of the right hand are curled around the coil in the direction of current flow (conventional current, flow of positive charge) through the windings, the thumb points in the direction of the field inside the coil. The side of the magnet that the field lines emerge from is defined to be the north pole.
The main advantage of an electromagnet over a permanent magnet is that the magnetic field can be rapidly manipulated over a wide range by controlling the amount of electric current. However, a continuous supply of electrical energy is required to maintain the field.