The scattering matrix algorithm is a popular numerical method for the diffraction of optical waves by periodic surfaces. The computational domain is divided into horizontal slices and, by a clever recursion, an approximated operator, mapping incoming into outgoing waves, is obtained. Combining this with numerical schemes inside the slices, methods like RCWA and FMM have been designed. The key for the analysis is the scattering problem with special radiation conditions for inhomogeneous cover materials.