You open the oven, the cake looks perfect, and twenty minutes later there is a crater in the middle of it. It is the most common thing that goes wrong in a home kitchen, and it is almost always one of these six.
1. The oven door was opened too early
A cake rises because steam and gas push the batter up before the structure sets. Open the door before that structure has set and the cold air drops the middle straight back down. Leave it alone until at least three quarters of the baking time has gone. If you need to turn the tin, do it quickly, and late.
2. It was not actually baked
A browned top is not the same as a baked cake. Test in the centre, not near the edge: a skewer should come out with a few dry crumbs and no wet batter on it. The cake should also have started to pull very slightly away from the side of the tin, and the top should spring back when you press it lightly.
3. Too much raising agent
More baking powder does not make a better rise. It makes a fast rise with nothing to hold it up, so the cake climbs and then falls. Measure it level rather than heaped, and check the date on the tin. Old baking powder is a different problem with the same ending.
4. The batter was overmixed after the flour went in
Creaming butter and sugar properly is worth the time. Beating hard once the flour is in is not: it builds the gluten that makes a cake tough and it knocks out the structure you have just built. Fold the flour through until it disappears, then stop.
5. The oven is not the temperature it says it is
Most home ovens run hot or cold, some of them by a lot, and nothing on the dial tells you which. An oven thermometer is inexpensive and it answers the question in one bake. Too hot sets the outside before the middle has finished rising and the middle then falls; too cool and the cake never sets properly at all.
6. The tin was too small, or too full
Fill a tin about two thirds. Any fuller and the batter rises higher than its own structure can support. If you have batter left over, bake it as cupcakes rather than forcing it into the tin.
What to do with the one that sank
Do not throw it away. A sunken cake is still a good cake with a dip in it. Level the top off with a serrated knife and use it as a bottom layer, where the filling and the sponge above hide everything. Or break it up into a trifle, or roll it with a little buttercream into cake pops. Nobody eating it will ever know.
Baking theory, why sponges behave the way they do, and the mistakes worth avoiding are the whole first half of the baking class: see the classes.