The broad features of rapid eye movement (REM) sleep are reviewed. Memory storage in the brain is probably quite unlike that in a digital computer, being distributed, superimposed and robust. Such memory systems are easily overloaded. If the stored memories share common features, random stimulation often produces mixed outputs. Simulations show that such overloading can be reduced by a process we call 'reverse learning'. We propose that this process is what is happening in REM sleep and that it explains in an unforced manner the condensation commonly found in dreams. Evidence for and against the proposed theory is discussed and several alternative theories are briefly described. The absence of REM sleep in the Enchidna and in two species of dolphins (that have relatively large brains) suggests that REM may allow the brain to be smaller than if REM were lacking.