Remember that “real world magnets” are ferromagnetic substances—they have a net overall spin. Again this is a quantum mechanical spin, but it’s okay to think of it as spin “up” or “down.” In a ferromagnet all of these spins are pointing in the same direction. If you put the “up” ends of a magnet together, they will repel—the magnetic fields are pushing in opposite directions. If you put an “up” end next to a “down” end, they will attract—the magnetic fields are working in the same direction, just like the electron spins are aligned within the magnet.