The general physical features and a mathematical description of spectral diffusion in glasses at low temperatures is considered. The condition is found for when spectral diffusion can be treated as a Markovian process. The physical reason for the Lorenzian form of a two-level system spectral line shape is considered. For the case when spectral diffusion is not Markovian it can be described by a distribution functional or a characteristic functional. The evaluation of the characteristic functional is reduced to solving a differential equation of second order and the evaluation of an integral. The theory is applied to two-pulse and three-pulse echo decay. The relationship between the theoretical results and available experimental data is discussed.