The freshness of coffee plays an important role in how coffee tastes. Like food, the fresher the ingredients the better the flavour. As freshly baked bread tastes better than bread a week old, so do freshly roasted coffee beans. The two processes which affect the length of time coffee stays fresh for are roasting and grinding.
In green bean form, coffee can stay fresh for up to 2 years. However, once it has been roasted it only stays fresh for up to 2 weeks. Ideally you should purchase your coffee in small amounts - only as much as you would use in a 1-2 week period. Coffee beans should be stored in airtight containers in a dark, dry and cool location.
If you have to buy more then a 2 week supply of coffee beans, you should freeze part of this purchase. Freeze the beans in a waterproof and airtight container and they will stay fresh for up to a month.
Frozen coffee beans must be allowed to fully defrost, between 2-4 hours at room temperature, before they can be ground; and great care must be taken to ensure that no ice from the freezer comes into contact with the beans, as moisture will cause them to deteriorate.
Once coffee has been ground, it should be used as soon as possible. Air is coffee's worst enemy, and as a ground coffee bean has a much larger surface area then a whole coffee bean, it is therefore more exposed to air and becomes stale quicker.
If you do not have a coffee grinder at home and so buy your coffee pre-ground, then it is a good idea to divide your coffee supply into several smaller portions. Keep each portion in an airtight container and take coffee from only one of these portions at a time, using up all the coffee grounds before moving on to the next one.