Sustained spontaneous activity in the resting state brain represents the intrinsic state of the brain during most cognitive tasks. Electroencephalogram (EEG) measures of the resting state have shown potential as biomarkers for the evaluation of cognitive performance, but there is a lack of validation across health and different diseased populations. This study aims to decode cognitive function from resting-state EEG activity, and demonstrates that nonlinear dynamic features of EEG signals can be used to predict cognitive performance in healthy young adults, elderly adults with mild cognitive impairment (MCI), and patients with major depressive disorder (MDD) using the extreme gradient boosting (XGBoost) prediction model. In particular, the results showed that performance in cognitive task can be predicted by the resting-state EEG-based measures in these three populations (correlation coefficients between predicted values and observed true values were: r=0.39, p < 0.01; r=0.76, p < 0.001; and r=0.40, p < 0.001; respectively). Furthermore, we observed a U-shaped or inverted U-shaped distribution of multiscale fuzzy entropy index (MFEI) in healthy, aging and diseased populations, which symbolizes the law of complexity and health. The results suggest that the dynamic complexity of resting state EEG oscillations can predict certain dimensions of cognitive function in both health and mental illness, and highlights the nonlinear relationship between neurological measures and cognitive health status. These findings may provide insights into the development of treatments to improve cognition.