An electromagnet produces a magnetic field using an electric current. Winding an electrical conductor into a coil combines the fields from its turns; a long solenoid is an idealized example. Far from its ends, an air-core solenoid has approximatelywhere turns carry electric current over length . Reversing reverses the axial magnetic field. [ref]
The Feynman Lectures on Physics, Volume II by Richard Feynman and others. Section II.13–5, magnetic field of a straight wire and solenoid
A core with ferromagnetism can concentrate the magnetic flux, but its response depends on magnetic saturation and magnetic hysteresis. The constant-permeability air-core formula cannot simply be extrapolated to arbitrarily large core fields. A magnetic compass near a powered coil provides a qualitative test: switching or reversing the electric current changes the compass orientation.
Articles by others on the same topic
Electromagnets allow us to create controllable magnetic fields, i.e.: they act as magnets that we can turn on and off as we please but controlling an input voltage.
Compare them to permanent magnet: on a magnet, you always have a fixed generated magnetic field. But with an electromagnet you can control the field, and even turn it off entirely.
This type of "useful looking thing that can be controlled by a voltage" tends to be of huge importance in electrical engineering, the transistor being another example.