Electromagnets are a non-permanent magnets that produced magnetic field. The magnetic field is created by a flow of an electric current through the coil. The magnetic field disappears when the current ceases (or in the caseelectromagnets of a permanent electromagnet, the magnetic field is present until a current is applied).
As a current is passed through the coil, small magnetic regions within the material, called magnetic domains, align with the applied field. Therefore, causing the magnetic field strength to increase. As the current is increased, all of the domains eventually are aligned, a condition called saturation.
The main advantage of an electromagnet over a permanent magnet is that the magnetic field can be rapidly manipulated. By controlling the strength of the electric current, the magnetic field will have a wide range of values . However, a continuous supply of electrical energy is required to maintain the field operative (as noted, the exact reverse is true for a permanent electromagnet).
In applications where a variable magnetic field is not required, permanent magnets are generally superior. (Additionally, permanent magnets can be manufactured to produce stronger fields than an electromagnet of a similar size.)
Electromagnets are used in many situations where a rapidly- or easily-variable magnetic field is desired. An example of this would be the deflection of charged particle beams (cathode ray tube and mass spectrometer fall into this category).