The short version
Magnetism is what you get when the tiny magnetic moments of electrons line up instead of cancelling. A permanent magnet is a material that keeps them lined up. Modern magnets, especially neodymium-iron-boron, are among the quietly essential materials of the electrified economy: there are one or two in your phone, dozens in a car, and several hundred kilograms for each megawatt of a large direct-drive wind turbine.
How it works
Each electron has an intrinsic magnetic moment, associated with its spin. In most materials electrons pair off and the moments cancel. Iron, cobalt, nickel and several rare-earth elements have unpaired electrons, and in their ferromagnetic compounds a quantum effect, the exchange interaction, makes neighbouring moments align. The alignment is organised into domains separated by thin walls. An unmagnetised bar of iron is full of domains pointing different ways; magnetising it grows the favourably aligned domains at the expense of the others.
What distinguishes a good permanent magnet from a piece of soft iron is coercivity: resistance to being demagnetised. Soft iron (great for transformer cores and electromagnets) loses its magnetism as soon as the field is removed. A good permanent magnet holds on. In neodymium-iron-boron, the crystal strongly prefers to be magnetised along one axis, and fine grains with carefully engineered boundaries stop reversed domains from spreading.