Overfitting occurs when a model learns the training data too well, capturing noise and fluctuations, which results in poor generalization to new data. Underfitting happens when a model is too simple to capture the underlying patterns in the data, leading to high bias and poor predictive performance.