Why do cows and sheep chew constantly?
They are ruminating — bringing food back up from the stomach to chew it again — and the whole system exists to solve a problem no animal can solve directly: no mammal can digest cellulose.
The underlying problem. Grass is mostly cellulose, locked in tough cell walls. No mammal produces an enzyme that breaks it down. Ruminants get around this by outsourcing digestion to microbes.
The four compartments. A ruminant's stomach has four parts, only the last of which is equivalent to a simple stomach:
The rumen — a large fermentation vat containing billions of bacteria, protozoa and fungi that break down cellulose and release volatile fatty acids, which the animal absorbs as its main energy source. It is effectively a continuous microbial culture.
The reticulum, which works with the rumen and forms the food into a bolus for regurgitation. It also catches swallowed foreign objects.
The omasum, which absorbs water and further reduces particle size.
The abomasum — the "true" stomach, secreting acid and enzymes, digesting the food and the microbes themselves, which are a substantial source of protein.
Why the chewing is constant. Microbes work on surface area, so the food must be ground extremely fine. The animal grazes quickly, swallowing barely-chewed material, then rests and regurgitates it in boluses to chew properly — chewing the cud. Cattle can spend a large share of the day at it, and the saliva produced does critical work: it is alkaline, buffering the rumen against the acids fermentation produces.
What follows from this:
Ruminating is a health indicator. A cow that stops chewing the cud is generally unwell, and farmers watch for it. Modern collar sensors monitor rumination time for exactly this reason.
Sudden diet changes are dangerous, because the microbial population must adapt. Too much rapidly fermentable grain causes acidosis.
Methane is a by-product of rumen fermentation, which is why cattle are significant in agricultural emissions.