If preserved properly, whole coffee beans and even ground coffee can last for a long duration. Since coffee is dry, it is unlikely that the varieties you buy for at-home usage may develop mold or other types of spoilage caused due to moisture. However, depending on the way it is prepared, the storage life of coffee varies.
Coffee that has not been roasted will last lengthier than coffee that has. It also matters where you store your coffee: in the cupboard, in the refrigerator, or the freezer. For 3–4 months, coffee beans are kept in airtight containers in the freezer. Ensure the container is dry before freezing. It will last more if you preserve the iced coffee in a sealed jar in the fridge. It’s likely fine to consume for 3–4 days if preserved in this manner.
It is, however, unlikely to be much more appetizing. If you add milk or creamer to your cold brew, drink it inside 2 hours after allowing it to cool to room temperature. You can store it in the fridge for a few days.
Cold-brew coffee will survive considerably more in the fridge than made hot coffee. The cold-brew concentrate can be kept in the fridge for 7–10 days if kept in an airtight container. If you add a little water to the concentrate before preserving it, or if you keep cold brew from a café in the fridge, you should drink it within 3–4 days.