Germs love the middle temperatures — roughly room temperature is their paradise. So the fridge rule is a race: cooked food cools and goes into the fridge within two hours, in shallow containers so the cold reaches the middle fast.
Leftovers get three to four days, labelled with the date if you are wise, and reheating means properly hot all the way through — steaming, not warmish.
And the nose rule that ends arguments: when in doubt, throw it out. Dangerous germs often leave no smell at all, so a sniff can never declare food safe — but a doubt can always declare it done.