How can I know how long home-cooked food will stay good in fridge?
The USDA says to eat refrigerated leftovers within 4 days.

Be aware that how long you leave something out before refrigeration and the size of the container can shorten the edible lifetime. The gist is the longer it's warm, the more [likely] pathogens will be able to multiply to unsafe levels. A large container holds heat longer and takes longer to reach 40°F.

There's also some other interesting information on the linked page about safe storage durations for many store-bought items as well, including recommendations for how long it will stay good in the freezer. To be fair to @Allison's answer, many of the durations listed in that chart are 3-4 days or 3-5 days, though some are longer or shorter.