Stereoisomerism occurs when compounds have the same formula but different spatial arrangements of atoms.