Repeated dieting may lead to weight gain because the brain interprets the diets as short famines and urges the person to store more fat for future shortages, new research by the universities of Exeter and Bristol suggests.
This may explain why people who try low-calorie diets often overeat when not dieting and so don't keep the weight off.
By contrast, people who don't diet will learn that food supplies are reliable and they do not need to store so much fat.
The study, published in the journal Evolution, Medicine and Public Health, is based on observations of animals such as birds.
Animals respond to the risk of food shortage by gaining weight, which is why garden birds are fatter in the winter when seeds and insects are hard to find.
The authors studied a mathematical model of an animal that knows whether food is currently abundant or limited, but does not know when things will change, so must learn about the changeability before deciding how fat to be.
The model shows that if food supply is often restricted (as it is when dieting) an optimal animal - the one with the best chance of passing on its genes - should gain excess weight between food shortages.
Dr Andrew Higginson, Senior Lecturer in psychology at the University of Exeter, says: "Surprisingly, our model predicts that the average weight gain for dieters will actually be greater than those who never diet.
"This happens because non-dieters learn that the food supply is reliable so there is less need for the insurance of fat stores."
With more and more people becoming obese, scientists are looking for evolutionary reasons to explain why many find it hard to resist overeating.
Humans evolved in a world where food was sometimes plentiful and sometimes scarce - and in the latter case those with more fat would be more likely to survive.
Today, people can get into a vicious cycle of weight gain and ever more severe diets - so-called yo-yo dieting - which only convinces the brain it must store ever more fat.
The researchers' model predicts that the urge to eat increases hugely as a diet goes on, and this urge won't diminish as weight is gained because the brain gets convinced that famines are likely.
"Our simple model shows that weight gain does not mean that people's physiology is malfunctioning or that they are being overwhelmed by unnaturally sweet tastes," says Professor John McNamara, of the University of Bristol's School of Mathematics.
"The brain could be functioning perfectly, but uncertainty about the food supply triggers the evolved response to gain weight."
So how should people try to lose weight?
"The best thing for weight loss is to take it steady. Our work suggests that eating only slightly less than you should, all the time, and doing physical exercise is much more likely to help you reach a healthy weight than going on low-calorie diets," Dr Higginson says.
Explore further: Why frequent dieting makes you put on weight – and what to do about it