Random forests are a type of ensemble learning method used for classification and regression tasks. They operate by constructing multiple decision trees during training and outputting the mode of the classes (for classification) or the mean prediction (for regression) of the individual trees. This approach helps to improve the predictive accuracy and control overfitting.