An electromagnet is formed because of the relationship between electricity and magnetism. When an electric field is in motion, a magnetic field is induced. (Vice versa, when a magnetic field is in motion, an electric field is induced. This is how electrical generators work.)
The magnetic field around a wire looks like circles centered on the wire, at every point along the wire. So if you bend that wire into a loop, all of a sudden all these circles start passing through the middle of the loop; the magnetic field is concentrated in one area. Now if you "wind" the wire so that you have one loop after another, the magnetic field continues to be concentrated in the center of the solenoid (the winding) along the whole length of the wire.
The magnetic field has to pass through space to complete it's circuit. The ability of the magnetic field to pass through a material depends on its magnetic susseptability. A magnetic field passes through air just fine, but ferromagnetic materials such as iron actually amplify the magnetic field. This is because the material is magnetic, which means that it acts as millions of little magnets that add to the magnetic field created by the wire. So placing a ferromagnetic material, not just a "hard material" (concrete wouldn't work; in fact it would be worse than air).
We know that when current passes through a conductor magnetic field is produced around it.We also know that if the conductor is in circular form the strength of the magnetic field is increased in the centre of the loop. The strength of the magnetic field is, therefore,
(i)directly proportional to the current passing through the circular loop(ii) and inversely proportional to the radius of the loop.
If we increase the the number of loops (by introducing the insulated conductor) the magnetic field strength gets stronger by that many number of times. This principle applies to a solenoid, where the insulated condutor is wound in a number of windings/ loops. Now if we introduce a core of soft iron rod through the solenoid the magnetic effect is many fold increased and the entire core acts as a magnet. The strength of this electromagnet is proportional to (i) the current passing through the insulated windings (ii) the number of turns in the windings.
The use of the soft iron core has one advantage that it completely looses its magnetism, when the current in the loop is switched off. If we use steel instead of soft iron , it does not loose all its magnetism when current is stopped.
To make the electromagnet stronger, as already told we have to (1) increase the current passing in the conductor , (2)increase the the number of loops of the conductor. One more factor is that the more the air gap between the poles , the less the magnetic field strength. For this reason, to reduce the length of air gap between the poles the eletromagnet is bent like a U-shape. A U-shaped (or horse shoe type) electromagnet is very much stronger than an electromagnet of bar shape with other identical conditions.