A herd is a social group of certain animals of the same species, either wild or domestic. The form of collective animal behavior associated with this is called herding. These animals are known as gregarious animals.
The term herd is generally applied to mammals, and most particularly to the grazing ungulates that classically display this behaviour. Different terms are used for similar groupings in other species; in the case of birds, for example, the word is flocking, but flock may also be used for mammals, particularly sheep or goats. Large groups of carnivores are usually called packs, and in nature a herd is classically subject to predation from pack hunters.
Special collective nouns may be used for particular taxa (for example a flock of geese, if not in flight, is sometimes called a gaggle) but for theoretical discussions of behavioural ecology, the generic term herd can be used for all such kinds of assemblage.[ citation needed]
The word herd, as a noun, can also refer to one who controls, possesses and has care for such groups of animals when they are domesticated. Examples of herds in this sense include shepherds (who tend to sheep), goatherds (who tend to goats), and cowherds (who tend to cattle).
When an association of animals (or, by extension, people) is described as a herd, the implication is that the group tends to act together (for example, all moving in the same direction at a given time), but that this does not occur as a result of planning or coordination. Rather, each individual is choosing behaviour in correspondence with most other members, possibly through imitation or possibly because all are responding to the same external circumstances. A herd can be contrasted with a coordinated group where individuals have distinct roles. Many human groupings, such as army detachments or sports teams, show such coordination and differentiation of roles, but so do some animal groupings such as those of eusocial insects, which are coordinated through pheromones and other forms of animal communication.
A herd is, by definition, relatively unstructured. However, there may be two [ further explanation needed] or a few animals which tend to be imitated by the bulk of the herd more than others. An animal in this role is called a "control animal", since its behaviour will predict that of the herd as a whole. It cannot be assumed, however, that the control animal is deliberately taking a leadership role; control animals are not necessarily socially dominant in conflict situations, though they often are. Group size is an important characteristic of the social environment of gregarious species.
The reason why animals form herds can not always be stated easily, since the underlying mechanisms are diverse and complex. Understanding the social behaviour of animals and the formation of groups has been a fundamental goal in the field of sociobiology and behavioural ecology. Theoretical framework is focused on the costs and benefits associated with living in groups in terms of the fitness of each individual compared to living solitarily. Living in groups evolved independently multiple times in various taxa and can only occur if its benefits outweigh the costs within an evolutionary timescale. Thus, animals form groups whenever this increases their fitness compared to living in solitary. 
The following includes an outline about some of the major effects determining the trade-offs for living in groups.
Perhaps the most studied effect of herds is the so-called dilution effect. The key argument is that the risk of being preyed upon for any particular individual is smaller within a larger group, strictly due to the fact that a predator has to decide which individual to attack. Although the dilution effect is influenced by so-called selfish herding, it is primarily a direct effect of group size instead of the position within a herd. Greater group sizes result in higher visibility and detection rates for predators, but this relation is not directly proportional and saturates at some point, while the risk of being attacked for an individual is directly proportional to group size. Thus, the net effect for an individual in a group concerning its predation risk is beneficial.  
Whenever groups, such as shoals of fish, synchronize their movements, it becomes harder for predators to focus on particular individuals. However, animals that are weak and slower or on the periphery are preferred by predators, so that certain positions within the group are better than others (see selfish herd theory). For fit animals, being in a group with such vulnerable individuals may thus decrease the chance of being preyed upon even further. 
The effect of collective vigilance in social groups has been widely studied within the framework of optimal foraging theory and animal decision making. While animals under the risk of predation are feeding or resting, they have to stay vigilant and watch for predators. It could be shown in many studies (especially for birds) that with increase in group size individual animals are less attentive, while the overall vigilance suffers little (many eyes effect). This means food intake and other activities related to fitness are optimized in terms of time allocation when animals stay in groups. 
However, some details about this concepts remain unclear. Being the first to detect predators and react accordingly can be advantageous, implying individuals may not fully be able to rely only on the group. Moreover, the competition for food can lead to the misuse of warning calls, as was observed for great tits: If food is scarce or monopolized by dominant birds, other birds (mainly subordinates) use antipredatory warning calls to induce an interruption of feeding and gain access to resources. 
Another study concerning a flock of geese suggested that the benefits of lower vigilance concerned only those in central positions, due to the fact that the possibly more vulnerable individuals in the flock's periphery have a greater need to stay attentive. This implies that the decrease in overall vigilance arises simply because the geese on the edge of the flock comprise a smaller group when groups get large.   A special case of collective vigilance in groups is that of sentinels. Individuals take turn in keeping guard, while all others participate in other activities.  Thus, the strength of social bonds and trust within these groups have to be much higher than in the former cases.
Hunting together enables group-living predators, such as wolves and wild dogs, to catch large prey, what they are unable to achieve when hunting alone. Working together significantly improves foraging efficiency, meaning the net energy gain of each individual is increased when animals are feeding collectively. A group of Spinner dolphins is for instances able to force fish into a small confined space, which makes capturing prey particularly easy, as there is no way for the latter to flee. Furthermore, large groups are able to monopolize resources and defend them against solitary animals or smaller groups of the same or different species. It was shown that larger groups of lions tend to be more successful in protecting prey from hyenas than small ones.  Being able to communicate the location and type of food to other group members may increase the chance for each individual to find profitable food sources, a mechanism which is commonly known to be used by bees, which use a so-called Waggle dance, and several species birds using food calls.
In terms of Optimal foraging theory, animals always try to maximize their net energy gain when feeding, because this is positively correlated to their fitness. If their energy requirement is fixed and additional energy is not increasing fitness, they will use as little time for foraging as possible (time minimizers). If on the other hand time allocated to foraging is fixed, an animal's gain in fitness is related to the quantity and quality of resources it feeds on (Energy maximizers). 
Since foraging may be energetically costly (searching, hunting, handling, etc.) and may induce risk of predation, animals in groups may have an advantage, since their combined effort in locating and handling food will reduce time needed to forage sufficiently. Thus, animals in groups may have shorter searching and handling times as well as an increased chance of finding (or monopolizing) highly profitable food, which makes foraging in groups beneficial for time minimizers and energy maximizers alike.  
The obvious disadvantage of foraging in groups is (scramble or direct) competition with other group members. In general, it is clear that the amount of resources available for each individual decreases with group size. If the resource availability is critical, competition within the group may get so intense, that animals no longer experience benefits from living in groups. However, only the relative importance of within- and between-group competition determines the optimal group size and ultimately the decision of each individual whether or not to stay in the group. 
Since animals in groups stay near each other and interact frequently, infectious diseases and parasites spread much easier between them compared to solitary animals. Studies have shown a positive correlation between herd size and intensity of infections, but the extent to which this sometimes drastic reduction in fitness governs group size and structure is still unclear.  However, some animals have found countermeasures such as propolis in beehives or grooming in social animals.
Staying together in groups often brings energetic advantages. Birds flying together in a flock use aerodynamic effects to reduce energetic costs, e.g. by positioning themselves in a V shaped formation.  A similar effect can be observed when fish swim together in fixed formations.
Another benefit of group living occurs when climate is harsh and cold: By staying close together animals experience better thermoregulation, because their overall surface to volume ratio is reduced. Consequently, maintaining adequate body temperatures becomes less energetically costly. 
The collective force of a group mobbing predators can reduce risk of predation significantly. Flocks of raven are able to actively defend themselves against eagles and baboons collectively mob lions, which is impossible for individuals alone. This behaviour may be based on reciprocal altruism, meaning animals are more likely to help each other if their conspecifics did so earlier. 
Animals living in groups are more likely to find mates than those living in solitary and are also able to compare potential partners in order to optimize genetic quality for their offspring. 
Domestic animal herds are assembled by humans for practicality in raising them and controlling them. Their behaviour may be quite different from that of wild herds of the same or related species, since both their composition (in terms of the distribution of age and sex within the herd) and their history (in terms of when and how the individuals joined the herd) are likely to be very different.
The term has acquired a semi-technical usage in behavioral finance to describe the largest group of market investors or market speculators who tend to "move with the market", or "follow the general market trend". This is at least a plausible example of genuine herding, though according to some researchers it results from rational decisions through processes such as information cascade and rational expectations. Other researchers, however, ascribe it to non-rational process such as mimicry, fear and greed contagion. "Contrarians" or contrarian investors are those who deliberately choose to invest or speculate counter to the "herd".