Groups of more than 5 farm animals you collect will stack with each other to help with server lag. A stacked mob can be identified by reading it’s name when hovering over the animal:
A stacked cow

Killing a stacked mob will reduce the number of animals in that stack by somewhere between 1 and 5, depending on the damage dealt.

Feeding the stacked animal will split it, allowing the split off mobs to breed:
How stacked mobs breed

The baby will stack with any other babies nearby. Once the animals have bred, the parents will form their own stack until their breeding timers reset, after which they will re-stack with the other mobs.

For sheep, shearing a stacked sheep will split it off, creating a new stack of sheared sheep:
Shearing a stacked sheep

Stacked chickens lay eggs at a faster rate, comparable to having all the chickens unstacked.
Once a stack of mobs hits 20, a new stack will be started. Named mobs will never stack.