When calculating electrical energy we use formulas that are hard to reconcile with those of mechanical energy yet each can be converted to the other. Electrical energy can be equated to mechanical energy because we have chosen electrical units to make them so. Whilst mechanical energy is mostly about the interactions of whole particle structures via photon energies, electrical energy is mostly about the interaction of the outer electron particles of structures via photons.
Electrons gather energy from the environment on behalf of nuclear particles. To perform that duty they need their own space and therefore interact with other electrons via photon energies so as to keep at a distance. Electrons are energy linked to protons because of their energy desires but less so when they are obliged to occupy positions furthest away from nuclei. In fact outer electron can link to more than one nuclei as with covalent, ionic and metallic bonding.
The metallic bonding in silver, copper gold and aluminium is such that outer electrons cannot make up their minds where they can best serve protons and they wander from atom to atom moving other electrons as they do so but all the while providing an energy feed from the environment that links them to protons.
Such electrons are not free but we can give them a directional flow that moves them in a cascade fashion round a circuit via their light speed photon energy interactions. We do so by providing a voltage source that delivers surplus electrons to one of its poles and removes electrons from its other pole.
Any move one outer electron makes almost immediately instigates movements in other electrons via light speed (300,000 kilometres a second) photon interactions. It is why energy can be conveyed over vast differences very quickly.
We should not think of electrons continuously on the move. They are generally spending considerably more time in atoms linking to protons than they are moving between atoms. Typical progress of an electron along a wire is a half metre every hour. When the moving electrons encounter an electrical load like a motor, heater or light electrons have to gang up and jointly a push that drives that load.
Electrons have a property called spin. I believe it is the result of their internal energy fragments spinning and related to the direction in which the electron is travelling. Some of the photons exchanged by electrons are spun off them and when many electrons have like directions of motion they spin out low level photon energies in the anti clockwise direction to their travel that are attracted back into the photon flows being exchanged by electrons.
The magnetic field that we see circling clockwise around a current carrying wire is actually photon energies being flung out from electrons with like direction spin as a result of their many like direction motions. We see the magnetic field as circular, related to the current flow and diminishing with distance from the wire but the field is really of photon energies that spiral outward from electrons and then spiral inward to electrons.
When the current related energy links are rising some of the driving energies go toward growing the magnetic field energy and when the current related energy links are falling the now collapsing magnetic field energy is trying to sustain the current flow. This is precisely what self induction is.
When two adjacent currents flow in opposite directions the circling photons passing between have like direction but want their own space and in pushing one another apart push the wires apart. When currents flow in the same direction photon flows between them are in conflict and many choose to go around both wires and that draws the wires together.
We should not think of neutrons, protons and electrons as being of fixed mass energies as they take on board and release photon energies that are general tiny relative to their mass energy. Nor should we think of photon energies as fixed. Like particle energies that interact via photons, photon energies interact by exchanging tiny portions of their energies. Magnetic photon energy interactions enable all electrical machines to work.
Electromagnets are just wire coils producing high volume photon flows. Soft iron is much used to support such photon flows because its outer electrons will align with and support such flows, even when they are reversing rapidly as with alternating circuits.
Permanent magnets are hard, rigid particle structures whose outer electrons have been given a like alignment during the manufacturing process by a powerful electromagnet.