Automatic sleep staging on an online basis has recently emerged as a research topic motivated by fundamental sleep research. The aim of this paper is to find optimal signal processing methods and machine learning algorithms to achieve online sleep staging on the basis of a single EEG signal. The classification performance obtained using six different EEG signals and various signal processing feature sets is compared using the kappa statistic which has very recently become popular in sleep staging research. A variable duration of the EEG segment (or epoch) to decide on the sleep stage is also analyzed. Spectral-domain, time-domain, linear, and nonlinear features are compared in terms of performance and two types of machine learning approaches (random forests and support vector machines) are assessed. We have determined that frontal EEG signals, with spectral linear features, epoch durations between 18 and 30 seconds, and a random forest classifier lead to optimal classification performance while ensuring real-time online operation.