Thomas Devine, a materials science and engineering professor at the University of California, Berkeley, provides this answer.
Stainless steels are iron-based alloys primarily known for their generally excellent corrosion resistance, which is largely due to the steel's chromium concentration. There are several different types of stainless steels. The two main types are austenitic and ferritic, each of which exhibits a different atomic arrangement. Due to this difference, ferritic stainless steels are generally magnetic while austenitic stainless steels usually are not. A ferritic stainless steel owes its magnetism to two factors: its high concentration of iron and its fundamental structure.
The metallic atoms in an austenitic stainless steel are arranged on a face-centered cubic (fcc) lattice. The unit cell of an fcc crystal consists of a cube with an atom at each of the cube's eight corners and an atom at the center of each of the six faces. In a ferritic stainless steel, however, the metallic atoms are located on a body-centered (bcc) lattice. The unit cell of a bcc crystal is a cube with one atom at each of the eight corners and a single atom at the geometric center of the cube. Alloying the stainless steel with elements such as nickel, manganese, carbon and nitrogen increases the likelihood that the alloy will possess the fcc crystal structure at room temperature. Chromium, molybdenum and silicon make it more likely that the alloy will exhibit the bcc crystal structure at room temperature.
The most popular stainless steel is Type 304, which contains approximately 18 percent chromium and 8 percent nickel. At room temperature, the thermodynamically stable crystal structure of 304 stainless steel is bcc; nevertheless, the alloy's nickel concentration, as well as the small amounts of manganese (about 1 percent), carbon (less than 0.08 percent) and nitrogen (about 0.06 percent), maintains an fcc structure and therefore the alloy is nonmagnetic. If the alloy is mechanically deformed, i.e. bent, at room temperature, it will partially transform to the ferritic phase and will be partly magnetic, or ferromagnetic, as it is more precisely termed.
Popular ferritic stainless steels are iron-chromium binary alloys with 13 to 18 percent chromium. These alloys are ferromagnetic at room temperature. Like all ferromagnetic alloys, when heated to a high enough temperature--their Curie temperature--the ferritic stainless steels lose their ferromagnetism and become paramagnetic--that is, they do not retain their own magnetic field but continue to be attracted to external ones.
A piece of ferritic stainless steel is typically unmagnetized. When subjected to a magnetic field, however, it will become magnetized and when this applied magnetic field is removed the steel remains magnetized to some degree. This behavior is a consequence of the steel's microstructure. Specifically, in its natural state ferritic steel consists of small regions called magnetic domains, which are fully magnetized, but in general the direction of magnetization is different in each domain. As a result, the sum total of all the domains gives the piece a zero magnetic moment. An external magnetic field orients these magnetic domains. Depending on the steel and the applied field, the orientation is achieved by a combination of selective growth or shrinking of particular domains and the rotation of magnetization within the domains. If the applied field is sufficiently strong, the steel will retain a significant fraction of its magnetization as long as the steel has an adequate number of imperfections that keep the domains from rotating and growing or shrinking.
Fundamentally, the reasons why ferritic stainless steels are ferromagnetic while austenitic stainless steels are not are quantum-mechanical in nature. Suffice it to say a ferromagnetic metal consists of atoms that have an incomplete inner core of electrons and a crystal structure that results in a high density of electron states in the energy bands formed from the incomplete atomic inner core. It also has an atomic spacing that allows for exchange effects among electrons in the energy bands associated with the incomplete inner-core level. If the atoms in the metal crystal are too widely spaced, the exchange effects are too small to cause alignment of the magnetic moments of neighboring atoms and the crystal will not exhibit ferromagnetism. The requirement of a high density of states stems from the Pauli Exclusion Principle. This principle prohibits electrons with the same spin from occupying the same energy level. Consequently, if the density of electron states is relatively small, electrons will need to occupy higher energy states in order for all to have the same spin. If the increase in energy resulting from the occupancy of higher energy levels exceeds the decrease in energy resulting from electron exchange energy, the structure will not be ferromagnetic.