If you take your coffee seriously—or, at minimum, don't want to drink sludge from a cup—you should learn how to store coffee properly. After all, coffee is really only two ingredients: water and coffee beans. So if you want to enjoy a cup of coffee that tastes as good as possible, you should know how to store coffee beans correctly. That's the best way to ensure that the coffee beans you're using to make your coffee are as fresh and flavorful as possible, and these tips for storing coffee beans are true whether you buy beans from the grocery store or an artisanal third wave coffee shop—or even if you roast your own beans at home.

The first step is figuring out what kind of beans to buy, and for best flavor and long-term storage potential, you want to buy whole beans and grind them as you need them, rather than getting pre-ground coffee. These whole beans are easier to store than their pre-ground counterparts, and they retain a fresh flavor for longer. As Dillon Edwards, founder of Parlor Coffee in Brooklyn, New York, tells Bon Appetit, "Fresh-ground coffee has more of its inherent aromatics preserved, and you'll get a sweeter, livelier cup . . . With high-quality specialty coffees, that's really what you're paying for."

Once you have your preferred roast of whole beans, you need to figure out where to store your coffee so that they stay fresh for as long as possible. There's some conflicting opinions as to whether you should keep your coffee unrefrigerated in the pantry or in the fridge or freezer. A coffee study from 2016 found that's better to keep coffee beans refrigerated in order to get a more even grind, but most coffee experts advise against keeping coffee beans in the fridge. It'll bring the oils in the coffee beans to the surface quicker and age them, and the beans, which are porous, might absorb ambient moisture and even scents.

You can store your beans in the freezer for up to a month if you know you're not going to drink them all immediately. But you shouldn't take the beans from the freezer straight to the cup, either. The experts at the National Coffee Association recommend that, if you really need to freeze your coffee beans, you should, "quickly remove as much as you need for no more than a week at a time, and return the rest to the freezer before any condensation forms on the frozen coffee."

The best way to store your coffee beans is in an airtight container on a cool shelf that's not sitting in direct light. You can use a Mason jar, though there are also some heavy duty vacuum-sealed coffee containers out there if you're really serious about keeping the oxygen out of your coffee beans. You also want to use your coffee quickly, so you're not letting the beans sit on the counter and age; the closer you're using the coffee beans to their roast date, the better quality they'll be—and that's as good a reason to drink more coffee as I've ever heard.