How is a magnetic field produced?

when a current runs through a conductor
when electrons move through a circuit
when an electromagnetic field interacts with a magnet
when an object has an electric charge

A magnetic field is produced when a current runs through a conductor or when electrons move through a circuit. This is due to the movement of charged particles creating a magnetic force.

Additionally, a magnetic field can also be produced when an electromagnetic field interacts with a magnet. Electromagnets, which are made by wrapping a coil of wire around a magnetic core and passing a current through the wire, create a magnetic field when the current is flowing.

Lastly, an object having an electric charge can also create a magnetic field, although this is less common than the other methods mentioned above. Some materials, known as ferromagnetic materials, have inherent magnetic properties due to the alignment of their atomic or molecular magnetic moments. In these cases, an object with an electric charge can influence the magnetic field around it.