A wire with an electric current passing through it, generates a magnetic field around it, this is a simple electromagnet. The strength of magnetic field generated is proportional to the amount of current.
Current (I) through a wire produces a magnetic field (B). The field is oriented according to the
right-hand rule.
In order to concentrate the magnetic field generated by a wire, it is commonly wound into a coil, where many turns of wire sit side by side. The magnetic field of all the turns of wire passes through the center of the coil. A coil forming the shape of a straight tube, a helix (similar to a corkscrew) is called a solenoid; a solenoid that is bent into a donut shape so that the ends meet is 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 magnifies 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.[1][2][3][4][5][6] 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.