A glass that is three quarters foam is frustrating and almost always explicable. The causes divide into what happens at home and what happens on draught, and temperature is behind most of them.
The temperature problem
Carbon dioxide dissolves readily in cold liquid and comes out of solution as it warms. A warm beer therefore releases its gas the moment it is disturbed, which is why the same can behaves entirely differently at four degrees and at eighteen.
The same applies to the glass. A warm glass, particularly one straight from a dishwasher, will foam a cold beer vigorously on contact.
The fix is straightforward: chill the beer properly before opening, and use a glass at room temperature or cooler rather than a warm one.
Agitation
A can or bottle that has been carried, jolted or transported recently holds gas in an unstable state and will foam violently.
Letting it rest for a few hours, ideally in a fridge, resolves it completely. This is why beer bought on the way home and opened immediately behaves worse than beer that has been sitting in the fridge since yesterday.
Pouring technique
Pouring straight down into an upright glass from height generates far more foam than necessary.
Tilting the glass to forty five degrees and pouring onto the sloping side controls the initial rush, then straightening the glass builds a deliberate head. Pausing for a few seconds when the foam rises too fast is normal for highly carbonated beers, and two or three stages is expected for a Belgian ale or a wheat beer.
Over-carbonation in the package
Sometimes the beer genuinely contains more gas than intended, and there are two common reasons.
Hop creep affects heavily dry-hopped beers. Enzymes carried on the hops break down sugars the yeast could not previously ferment, restarting fermentation in the can and producing extra carbon dioxide. The symptom is a can that hisses aggressively and gushes on opening, sometimes with a butterscotch note.
Infection produces the same result more dramatically. A wild organism consuming remaining sugars will over-carbonate a package and the beer usually tastes sour or odd alongside it.
Both are worth mentioning to the retailer or brewery, since a batch behaving this way is a production issue the brewery will want to know about.
Draught problems in a pub
On keg systems, foam usually indicates a technical fault rather than the beer.
Applied gas pressure that is too high forces excess carbon dioxide into the beer over time, and pressure that is too low lets gas break out in the line. Both produce foam and both are cellar settings rather than bad luck.
Warm beer lines are the other common cause. If the line running from the cellar to the bar is not properly cooled along its length, beer warms in transit and breaks out as foam at the tap. This is why a first pint after a quiet period is frequently foamy and the second is fine.
Dirty lines, worn washers and kinked tubing all contribute as well.
Nucleation and glassware
A scratched or heavily etched glass provides a great many nucleation sites, producing more bubbles than intended. That is desirable in moderation and excessive if the glass is damaged.
Residue does the opposite, killing the head entirely, which is why the same beer can foam uncontrollably in one glass and lie flat in another.
The practical routine is simple: cold beer, rested container, clean glass at room temperature, tilted pour. That combination resolves the great majority of foaming problems before they start.
When foam is the point
It is worth remembering that some beers are meant to foam enthusiastically. A wheat beer that pours without a substantial head has been poured wrong or served in a poor glass.
The distinction is between a controlled head that settles into a stable few centimetres and an uncontrolled eruption that fills the glass and leaves an inch of liquid.
The first is correct service. The second indicates one of the causes above, and working through them in order, starting with temperature, will resolve it in almost every case.