If you’re getting ahead of the game and baking pies in advance of when you want to serve them (or, should you find yourself with the exciting and rare predicament of having leftover pie), you may be wondering: What is the best way to store pie? How long can it sit out on the counter and when does it need to be refrigerated? Well, that depends.

The pie experts at Pillsbury suggest covering custard and cream pies with plastic wrap before refrigerating for up to two days. This is backed up by the USDA, which also recommends throwing away all perishable foods after they’ve been left at room temperature for more than two hours, since bacteria grow rapidly between the temperatures of 40ºF and 140ºF.

But the folks at Betty Crocker argue it’s OK to keep fruit-filled pies at room temperature, as long as it’s for two days or less; after that, the pies should head into the fridge.

Our advice? Be sure to refrigerate cream, custard, pumpkin, mousse, chiffon, or any other pies containing eggs or dairy as soon as they’ve cooled completely; they’ll keep for up to two days. (This includes savory pies like quiche, of course.)

Fruit pies can stand at room temperature for two days. If you need to store them longer, wrap them in plastic and put ’em in the fridge for up to another two days—but we hardly think they’ll be around that long.

You can successfully freeze many kinds of pie, including fruit pies, pumpkin pie, and pecan pie, but more delicate mousse and custard pies will not fare well. Neither will meringue.

When freezing pie, we advise wrapping well in a layer of plastic, then a layer of foil, to be sure it’s protected from freezer burn. It should last for a few months.

Check out our favorite Thanksgiving pies, and all our other pie recipes, plus intel on how to bake multiple pies at once.