Coffee is unique among artisanal beverages in that the brewer plays a significant role in its quality at the point of consumption. In contrast, drinkers buy draft beer and wine as finished products; their only consumer-controlled variable is the temperature at which you drink them.
Why is it that coffee produced by a barista at a cafe always tastes different than the same beans brewed at home?
It may be down to their years of training, but more likely it’s their ability to harness the principles of chemistry and physics. I am a materials chemist by day, and many of the physical considerations I apply to other solids apply here. The variables of temperature, water chemistry, particle size distribution, ratio of water to coffee, time and, perhaps most importantly, the quality of the green coffee all play crucial roles in producing a tasty cup. It’s how we control these variables that allows for that cup to be reproducible.

How strong a cup of joe?

Besides the psychological and environmental contributions to why a barista-prepared cup of coffee tastes so good in the cafe, we need to consider the brew method itself.
We humans seem to like drinks that contain coffee constituents (organic acids, Maillard products, esters and heterocycles, to name a few) at 1.2 to 1.5 percent by mass (as in filter coffee), and also favor drinks containing 8 to 10 percent by mass (as in espresso). Concentrations outside of these ranges are challenging to execute. There are a limited number of technologies that achieve 8 to 10 percent concentrations, the espresso machine being the most familiar.

Science helps optimize the coffee. (Chris Hendon, CC BY-ND)

There are many ways, though, to achieve a drink containing 1.2 to 1.5 percent coffee. A pour-over, Turkish, Arabic, Aeropress, French press, siphon or batch brew (that is, regular drip) apparatus – each produces coffee that tastes good around these concentrations. These brew methods also boast an advantage over their espresso counterpart: They are cheap. An espresso machine can produce a beverage of this concentration: the Americano, which is just an espresso shot diluted with water to the concentration of filter coffee.
All of these methods result in roughly the same amount of coffee in the cup. So why can they taste so different?

When coffee meets water

There are two families of brewing device within the low-concentration methods – those that fully immerse the coffee in the brew water and those that flow the water through the coffee bed.
From a physical perspective, the major difference is that the temperature of the coffee particulates is higher in the full immersion system. The slowest part of coffee extraction is not the rate at which compounds dissolve from the particulate surface. Rather, it’s the speed at which coffee flavor moves through the solid particle to the water-coffee interface, and this speed is increased with temperature.

The Coffee Taster's Flavor Wheel provides a way to name various tastes within the beverage.

A higher particulate temperature means that more of the tasty compounds trapped within the coffee particulates will be extracted. But higher temperature also lets more of the unwanted compounds dissolve in the water, too. The Specialty Coffee Association presents a flavor wheel to help us talk about these flavors – from green/vegetative or papery/musty through to brown sugar or dried fruit.
Pour-overs and other flow-through systems are more complex. Unlike full immersion methods where time is controlled, flow-through brew times depend on the grind size since the grounds control the flow rate.
The water-to-coffee ratio matters, too, in the brew time. Simply grinding more fine to increase extraction invariably changes the brew time, as the water seeps more slowly through finer grounds. One can increase the water-to-coffee ratio by using less coffee, but as the mass of coffee is reduced, the brew time also decreases. Optimization of filter coffee brewing is hence multidimensional and more tricky than full immersion methods.

What do they know that we don't? (Redd Angelo on Unsplash, CC BY)

Other variables to try to control

Even if you can optimize your brew method and apparatus to precisely mimic your favorite barista, there is still a near-certain chance that your home brew will taste different from the cafe’s. There are three subtleties that have tremendous impact on the coffee quality: water chemistry, particle size distribution produced by the grinder and coffee freshness.
First, water chemistry: Given coffee is an acidic beverage, the acidity of your brew water can have a big effect. Brew water containing low levels of both calcium ions and bicarbonate (HCO₃⁻) – that is, soft water – will result in a highly acidic cup, sometimes described as sour. Brew water containing high levels of HCO₃⁻ – typically, hard water – will produce a chalky cup, as the bicarbonate has neutralized most of the flavorsome acids in the coffee.
Ideally we want to brew coffee with water containing chemistry somewhere in the middle. But there’s a good chance you don’t know the bicarbonate concentration in your own tap water, and a small change makes a big difference. To taste the impact, try brewing coffee with Evian – one of the highest bicarbonate concentration bottled waters, at 360 mg/L.
The particle size distribution your grinder produces is critical, too.
Every coffee enthusiast will rightly tell you that blade grinders are disfavored because they produce a seemingly random particle size distribution; there can be both powder and essentially whole coffee beans coexisting. The alternative, a burr grinder, features two pieces of metal with teeth that cut the coffee into progressively smaller pieces. They allow ground particulates through an aperture only once they are small enough.
There is contention over how to optimize grind settings when using a burr grinder, though. One school of thought supports grinding the coffee as fine as possible to maximize the surface area, which lets you extract the most delicious flavors in higher concentrations. The rival school advocates grinding as coarse as possible to minimize the production of fine particles that impart negative flavors. Perhaps the most useful advice here is to determine what you like best based on your taste preference.
Finally, the freshness of the coffee itself is crucial. Roasted coffee contains a significant amount of CO₂ and other volatiles trapped within the solid coffee matrix: Over time these gaseous organic molecules will escape the bean. Fewer volatiles means a less flavorful cup of coffee. Most cafes will not serve coffee more than four weeks out from the roast date, emphasizing the importance of using freshly roasted beans.
One can mitigate the rate of staling by cooling the coffee (as described by the Arrhenius equation). While you shouldn’t chill your coffee in an open vessel (unless you want fish finger brews), storing coffee in an airtight container in the freezer will significantly prolong freshness.
So don’t feel bad that your carefully brewed cup of coffee at home never stacks up to what you buy at the café. There are a lot of variables – scientific and otherwise – that must be wrangled to produce a single superlative cup. Take comfort that most of these variables are not optimized by some mathematical algorithm, but rather by somebody’s tongue. What’s most important is that your coffee tastes good to you… brew after brew.