An electromagnet works on the principle of the magnetic effect of electric current. It is formed when a strong magnetic field is produced inside a solenoid to magnetise a piece of a magnetic material like soft iron. Electromagnets are made out of a coil of wire (wire curled in series). This is more effective in producing a magnetic field than just a wire running straight.
Working principle
The atoms in the nail are oriented in random directions, and individual magnetic fields cancel each other out. Under the influence of electric current, these atoms are reoriented to start pointing in the same direction. All these individual magnetic fields together create a strong magnetic field. As the current flow increases, this degree of reorientation also increases, resulting in a stronger magnetic field. Once all the particles are reoriented perfectly in the same direction, increasing current flow will not affect the magnetic field produced. At this point, the magnet is said to be saturated