How can two permanent magnets do work on each other?

If you put two magnets with opposite poles facing each other they will attract each other. If you put them with the same poles facing each other they will repel each other.

What is the mechanism behind this? A static $B$-field can do no work, and still the magnets will attract/repel.

  • 2
  • $\begingroup$ Thanks, didn't find that answer when I searched :) $\endgroup$ – Løiten Aug 18 '15 at 12:04
  • $\begingroup$ @Løiten : generally speaking you do work on the magnets when you pull them apart. Then when you let them go the magnetic fields convert potential energy into kinetic energy. They don't add any energy to the system. You did that. It's similar when you lift a brick. You do work on it. When you let it go, gravity converts potential energy into kinetic energy, but doesn't add any energy. $\endgroup$ – John Duffield Aug 18 '15 at 12:35