Pantry items in jars.

The art of grocery shopping lies in picking the best-tasting ingredients. But the science lies in buying them at the right moment and in the right quantity. This balance is seen most clearly when buying shelf-stable foods.

Knowing which foods with longer shelf lives you can keep in your pantry — and how long they can stay there — can save you money and make it easier for you to whip up a delicious meal without running to the store. So, let’s talk about which grocery items last for months (or even years!) so you always have the ingredients for a good meal on hand.

Here are five tips to keep your nonperishable purchases around even longer, stretching their shelf life (and your grocery budget!).

1. Understand the “best by” date vs. expiration date

When looking for foods with longer shelf lives, it helps to understand that the “best by” date on most nonperishable food packaging (sometimes labeled “sell by” or “use by”) is for quality, not safety. This is different than the expiration date on foods that can make you sick if spoiled, such as dairy products and meat.

A stamped “best by” date suggests that the food no longer tastes its absolute best, but for most dried, canned or shelf-stable foods, the deterioration is barely noticeable. Pasta and packaged soups, for example, can last years beyond the date printed, according to the U.S. Department of Agriculture (USDA).

Check out the USDA FoodKeeper App for the shelf life of any product you’re skeptical of.

2. Look for pantry favorites that last (almost) forever

Unopened peanut butter and dried pasta both last about two years in the pantry. Canned tuna can stay edible for up to three (but the packets only last for about half that). Granulated sugar can be kept pretty much indefinitely. You have nearly five years to use any fruit or vegetable in a can, except for acidic foods like tomato paste, which should be used within two years or less.

How long foods such as granola bars or oats last depends on the packaging, but you can count on being able to eat them for a good six months after the manufacturer’s “best by” date and not notice the difference.

3. Avoid buying certain pantry items too far ahead

Know your family: There’s no point in buying large quantities of flour if you never bake since it won’t even last a year. Whole grains, whole wheat flour and brown rice tend to go stale faster than the white or milled alternatives, so make sure to pay attention if you’re looking for healthy foods with long shelf lives.

Buying in large quantities ahead of time works well for items you know your family loves, but it can be risky when you branch out —you don’t want to get saddled with two extra boxes of a cereal nobody likes.

4. Check coupons and cash back offers for shelf-stable goods

A great way to save money on dry goods and pantry items is to buy them when you can snag a great offer from our website. Because pantry items last a while, you can take advantage of the savings whenever the coupon comes up, instead of waiting until you need that ingredient and having to pay full price.

5. Change out the in-store packaging

Even if a food might stay fine when sitting in the pantry for a long period, you can take steps to extend the shelf life once you open them. Transferring items like pasta, rice and sugar into sealable containers will keep them from drying out and from attracting pests that could ruin them. Properly storing potatoes, apples and onions in a cool, dark place — though not with each other — can keep them usable for months.

Future you will be grateful

When you’re having a busy week or just don’t feel like grocery shopping, you’ll be glad you have a stocked pantry of yummy ingredients that can help you pull together a meal in no time.