Surface codes work by arranging qubits on a two-dimensional lattice and encoding logical qubits into a larger number of physical qubits. This arrangement allows for the detection and correction of errors using local measurements, which are crucial in a quantum system.