A method for the automatic detection of episodes of wakefulness during sleep is presented. The algorithm is based on the evaluation of the alpha slow-wave index (ASI), a measure that has been developed to detect fluctuations of vigilance in daytime pharmaco-electroencephalogram studies. Its application to sleep data was validated with polysomnographic recordings from 16 elderly insomniacs and 16 young healthy subjects. The rate of agreement between the computerized procedure and the visual scoring of wakefulness was 94.0% for the insomniacs and 96.9% for the healthy subjects. The decision criterion used by the computer allowed the definition of a subject-adapted threshold for the detection of wake episodes. The method opens new perspectives for the automatic analysis of continuous 24-hour sleep-wake recordings.