It's best to grind coffee beans just before brewing. Grinding exposes more surface area to air, accelerating the loss of volatile compounds and leading to flavor degradation over time.