Electromagnet is simply an electric magnet, a magnet which needs electricity to show magnetic behaviour. When electricity passes, it behaves as a magnet but it is like ordinary metal when electricity is not passed through it.
The electromagnet was invented by William Sturgeon in 1824 A.D. However I would personally give some share of credit to Hans Christian Orsted, who discovered electric current creates a magnetic field. Whenever electricity is passing on a conductor, a magnetic field is created around it.
How is an Electromagnet made?
An electromagnet can be made using simple household materials. You’ll require batteries, insulated wires, an iron nail and a switch. First of all, you have to wind a wire around the nail as in the picture below. Then connect one end of the wire to an end of the battery through a switch and other ends of the wire to another end of battery. Congratulations, you got yourself an electromagnet. The nail behaves as a magnet in switch on condition and as an ordinary nail otherwise.
How does it work?
An electromagnet works on the principle that a conductor carrying electric current develops magnetic field around it. The direction of the magnetic field is given by cork-screw rule. If you are opening a bottle cap, you rotate anticlockwise the cap and it comes upward but it goes down when you rotate in another direction. Similarly according to cork-screw rule, if electricity is moving in the direction of movement of a cap (upward or downward), the magnetic field will be around in the direction you are moving the cap (anticlockwise or clockwise).
You were told above to wind the wire around the nail while making an electromagnet. The winding of wire is necessary because each turn develops a magnetic field around it. When we have a lot of winding, it overcrowds the magnetic field lines so that the magnetic field is strong. This magnetic field magnetizes the iron nail and hence it behaves as a magnet. So, Greater the number of winding, stronger your electromagnet gets.
Other than winding, strength of magnet depends upon the electric current you are using. If you increase current (add number of batteries), the magnet gets stronger. Also, the magnetic strength depends upon the material you are using, in our case iron.