Coffee can supremely confusing. It is the seed of a fruit that grows off an exceptionally finicky plant, which itself roots in hard-to-access parts of the world. Once the seed is obtained, it’s bagged and freighted thousands of miles to a roaster cooks it using a combination of math and feel. Then it is ground and brewed into coffee, both tasks that require a cupboard’s worth of gear.

The reality is that this gear controls very few of the variables that determine the quality of this coffee. Three things to keep in mind: your grinder and grind level, the brewing style and when it is you brew that seed into something drinkable. The latter is easiest to gloss over, and, according to Peter Giuliano, research director at the Specialty Coffee Association, perhaps the most misunderstood.

“There isn’t a perfect, catch-all way to describe how long coffee is going to be good for, really, because there are far too many variables to consider. But we do know the primary causes of coffee going stale,” Giuliano said. Here’s what you need to know about keeping coffee fresher for longer, according to experts.

Coffee Goes Bad in Two Ways

The gist, says Giuliano and the team behind the SCA’s new Coffee Freshness Handbook, is that coffee loses quality (a word many science-types balk at, as it’s often viewed as a subjective quality) by de-gassing and growth of “undesirable compounds.”

Prior to roasting, coffee beans carry the same level of carbon dioxide as the air around you; but once roasted, up to two percent of each bean’s weight may be carbon dioxide. Gas begins leaking from the bean the moment roasting ends, and the release of this gas leads to the loss of the coffee’s aromatics (also called volatile organic compounds) and the oxidization of the beans. The bad flavors that crop up are a result of age and oxidization.

You Might Want to Leave the Coffee in the Bag

Oxygen is the ultimate enemy of coffee beans, which is why most bags of coffee nowadays feature a small valve hole. This one-way hole is for de-gassing carbon dioxide to escape (so the bag doesn’t inflate and explode), and doesn’t allow oxygen into the bag. This means that the bag is primarily filled with carbon dioxide making its way out of the bag, and very, very little oxygen.

According to Giuliano, the carbon dioxide in the bag even acts like a “blanket” to cover the beans for oxygen, and that even if you’re re-opening the bag to make coffee, you aren’t losing much carbon dioxide. “If you dump all the beans into a new container — which contains oxygen — you are basically disposing of that valuable C02 blanket, and replacing it with oxygen-containing atmosphere,” Giuliano said. The effect of vacuum containers which remove the air from the interior of the canister, like Fellow’s new Atmos canister, remain untested, according to Giuliano.

Coffee Stays Fresh for Two Weeks

Generally speaking, drinking coffee within two weeks of it being roasted is best, Giuliano said. “It degrades very quickly after that. Certainly, by three months, the coffee is fully stale. However, these numbers change dramatically depending on packaging material and atmosphere.”