What is overfitting?

In short
Overfitting is when a machine learning model learns its training data too closely, including random noise and quirks, so it scores well on that data but poorly on new examples. It is a common problem when a model is more complex than the available data can support.
What overfitting means
A machine learning model learns patterns from example data. You show it many inputs with known answers, and it adjusts itself until its predictions match those answers. The goal is for the model to find patterns that also hold for data it has never seen.
Overfitting happens when the model learns the examples too well. Instead of finding the general pattern, it memorizes the details of the training data, including small random variations that have nothing to do with the real question. The model looks excellent on the examples it practiced with, but it fails when it meets new cases.
A simple comparison helps. Imagine a student who memorizes the answers to last year's practice test word for word. The student scores perfectly on that test. On a new test with different questions, the student struggles, because they learned the answers and not the subject.
Why it happens
Overfitting usually comes from a mix of three things. The first is a model that is too complex for the amount of data. A very flexible model has enough room to fit almost any set of points, including the noisy ones. The second is too little training data. With only a few examples, a model can find coincidences that look like rules. The third is training for too long, so the model keeps adjusting itself to the fine details of the examples.
Noise in the data makes the problem worse. Real data contains measurement errors, mislabeled examples, and random events. A model that treats every detail as important will treat this noise as a signal.
How to spot it
The main way to detect overfitting is to hold back some data. The model trains on one part of the dataset, called the training set. You then check its performance on a separate part it did not see during training, called the test set. Many teams also keep a validation set to tune the model before the final test.
If the model scores much higher on the training data than on the test data, it is probably overfitting. A large gap between the two results is the warning sign. A model that does poorly on both sets is a different problem, usually called underfitting, which means the model is too simple to capture the pattern.
Choose your metric carefully. The glossary defines accuracy as the number of correct predictions divided by the total number of predictions. Accuracy can hide problems when one class is much more common than the other, so check other metrics too.
How to reduce it
Several common techniques help. You can collect more training data, which makes random coincidences less likely to dominate. You can choose a simpler model, or reduce the number of input features the model uses. Regularization adds a penalty that discourages extreme settings in the model, which keeps it from bending too far toward the training examples. Stopping training early, when test performance stops improving, is another practical option.
Cross-validation is also useful. It splits the data into several parts and trains and tests the model on different combinations of them. This gives a more reliable picture of how the model will behave on new data than a single split.
Common mistakes
The most frequent mistake is testing on the training data. The score looks great, but it tells you little about real performance. Always keep a test set that the model never sees during training.
Another mistake is tuning the model again and again using the test set. Once the test set guides your choices, it stops being an honest check. Use a validation set for tuning and keep the test set for the final check.
Finally, do not assume that a high score means a good model. Look at how the score changes between training and new data, and ask whether the model would still make sense on examples it has never seen.
If you want precise definitions of terms such as accuracy, test set, and metrics, the Google Machine Learning Glossary is a good reference: https://developers.google.com/machine-learning/glossary
FAQ
Is overfitting the same as a model being wrong?
Not exactly. An overfitted model is often very accurate on its training data. The problem is that its accuracy does not carry over to new data, because it learned details that do not generalize.
Can a model overfit even if it has a lot of data?
Yes. A model can still overfit when it is very complex or trains for too long, even with plenty of data. More data reduces the risk but does not remove it entirely.
What is the difference between overfitting and underfitting?
Overfitting means the model learned the training examples too closely and fails on new data. Underfitting means the model is too simple to capture the pattern, so it performs poorly on both training and new data.
How do I know if my model is overfitting?
Compare its results on the training data with its results on a separate test set. If the training score is much higher than the test score, overfitting is likely.
Sources
This page is based on the official documentation below. Read it for full detail.
Overfitting — official documentation ↗