When a current flows through a conducting wire a magnetic field is produced around the wire. The strength of the magnetic field depends on the current through the wire and the distance from the wire.
Shaping a wire to form a solenoid increases the strength of the magnetic field created by a current through the wire. The magnetic field inside a solenoid is strong and uniform
The magnetic field around a solenoid has a similar shape to that of a bar magnet. Adding an iron core increases the strength of the magnetic field of a solenoid. An electromagnet is a solenoid with an iron core