Pretty much nothing beats a batch of soft, chewy cookies fresh from the oven. But unless you’re baking for a crowd, you’re probably gonna have some leftover treats. And with each passing day, they’ll veer a little closer toward hockey puck territory.

This fate is, sadly, unavoidable (unless you pump your cookies full of chemical preservatives. But please, don’t do that). The good news is that the right baking and storage techniques can keep homemade cookies soft and chewy for longer so you have more time to enjoy them in all their glory. And it’s super easy. Here’s how to keep cookies soft.

How to Make Soft Cookies

Before we talk about how to keep homemade cookies soft, let’s quickly brush up on how to make soft, chewy cookies in the first place.

Some cookies—like biscotti or gingersnaps—are meant to be crunchy. But ones like chocolate chip or oatmeal can go either way. So what’s the secret to achieving a fudgy texture instead of one that’s thin and crispy? It all comes down to moisture, people.

Scooping your cookies into tall mounds instead of flattening them with your palm, and underbaking them by a minute or two will help them retain a dense, chewy bite, explains Jenny McCoy, pastry baking arts chef-instructor at the Institute for Culinary Education in New York. Adding more moisture to your dough in the form of extra butter, egg yolks, or brown sugar will make your cookies even softer. Here’s how to adjust your favorite cookie recipe to achieve chewy perfection.

Why Soft Cookies Turn Hard

Cookies go from chewy to crunchy for exactly the reason you might expect: They start to dry out. “The loss of moisture to the air is what will turn soft cookies hard,” says executive chef Leah Henderson, who oversees the pastry and dessert program for D’Amico & Partners restaurants.

This process actually starts as soon as you pull them out of the oven and let them cool. (Which is why still-warm cookies are the softest of all.) “The remaining trapped moisture in the cookies is in a constant process of evaporating from the flour,” explains Jerrelle Guy, author of Black Girl Baking. At the same time, starches in the flour begin to crystallize and harden. The two processes combined are what eventually turns a fresh, soft cookie into a hard, stale one, Guy says.

How to Keep Cookies Soft

You can’t completely prevent moisture loss from happening, so all cookies will turn stale eventually. But lucky for you, cookies that have more moisture to begin with will stay soft and chewy for longer.

So consider tweaking the ingredient ratios as mentioned above and underbake them a little bit. “Pull them out of the oven when the center is still a little raw,” Guy says. (They’ll keep cooking when you take them out of the oven.) Then, pack the cookies up until they’re just cool enough that they don’t fall apart when you try to lift them. The extra moisture from the still-warm cookies will help them stay fresher longer, says Guy.

As for packing? Guy and Henderson both recommend putting them in an airtight container or zip-top bag, which will help slow moisture loss. If you need to layer cookies on top of each other, a piece of plastic wrap between each layer will keep them from sticking to one another. This method will keep them fresh for up to a week. (To make them even softer when you’re ready to eat, stick the cookies in the microwave for 10-15 seconds with a glass of water next to them, Henderson says.)

For longer-term storage, stick your cookies in the freezer. Layer completely cooled cookies between sheets of parchment paper and wrap the layered stack in plastic wrap, Henderson recommends. Then place the stack in an airtight container. If there’s any extra space in the container, fill it with bubble wrap. It’ll minimize airflow and keep moisture from evaporating, Henderson says. When it’s time to eat, just let the cookies come to room temperature.

Got a batch of vegan cookies?Same rules apply. “Assuming you’re keeping the same amount of sugar, binder, and fat, they should last as long as their non-vegan brethren,” Guy says.

Give Gluten-Free Cookies Some TLC

Without the structural power of gluten, GF cookies tend to dry out a little quicker. You can make them softer and chewier from the get-go by using a flour blend that’s higher in protein or contains tapioca flour, both of which provide elasticity, says Guy.

Store them in an airtight container, just like conventional cookies, for up to 48 hours. If you plan to eat them after that, they’ll stay fresher if you stick them in the freezer, Guy says.

Drooling yet? Here’s a single-serving chocolate chip cookie to give you immediate satisfaction.