We have demonstrated how individual-level selection can favor the emergence of in-group bias in a world of dynamic social ties and group identities. We consider the full continuum of strategies for both in-group and out-group interactions, not just those that show in-group favoritism. We also include strategies which do not discriminate between in-group and out-group members, as well as strategies which give preferential treatment to out-group members. We derive the conditions for natural selection to favor the recognition of group membership and for the ensuing success of in-group favoritism (Fig. 2).

Previous theoretical studies have examined the thought experiment of the green-beard effect (or tag-based cooperation), finding that cooperation can evolve when similar others receive preferential treatment15,18,19,21,22. Phenotypic tags in these models can be regarded as a sort of minimal grouping. In contrast to our present model, these previous models assume a priori that individuals never cooperate with out-group members and therefore group structure (as in an island model) supports the evolution of within-group helping48,49. Yet empirical evidence indicates that although people exhibit more in-group cooperation than out-group cooperation, cooperation with out-group members is still far above zero8,44. Thus unlike previous models, we allow the possibility of both in-group and out-group cooperation and determine the conditions under which preferential in-group cooperation is favored by selection. As seen experimentally, we find the emergence of in-group bias together with substantial levels of out-group cooperation.

A second set of previous models consider in-group helping and out-group harming in the context of explicit intergroup conflict with discrete (binary) strategies20,24,50. Two of these models use simulations to explore the evolution of such ‘parochial altruism’ and find that explicit inter-group conflict is needed for selection to favor bias20,24: groups with more in-group helpers and/or out-group harmers battle and replace other groups. A third model also considers intergroup conflict as the driving force behind bias and derives analytical results. However, we note that their approach requires infinitely many groups of fixed size, applies only to additive games and only gives the direction of selection (rather than any actual evolutionary dynamics) for mutant invasion attempts at a locus without polymorphism at the other locus. Unlike these models, we show that sensitivity to group identity need not be the result of such intergroup conflict, but instead can result from particular population structures. Furthermore, our approach yields general analytical results, characterizing the full evolutionary dynamics of our system and can easily be applied to a range of “in-group/out-group” interactions (including, but not limited to, additive games).

Our mutation-selection analysis shows that increasing the strategy mutation rate µ always makes it harder for cooperation to predominate (Fig. 3c), but that this is not the case for the set mutation rate v: there is an optimal level of ϑ for promoting in-group cooperation (Fig. 3d). In our model, prosperous groups tend to attract new individuals, which can be seen as ‘payoff-biased migration’45,46,47. However, this non-random migration cannot promote the success of in-group solidarity if the set mutation rate, or ‘confusion about the other's set’, is too low. Without flexibility in group identity (ϑ → 0) all individuals eventually end up in the same group and then the system is prone to exploitation of in-group members. This is why some out-group favoritism can evolve under this circumstance. On the other hand, when the set mutation rate is excessively high (ϑ → ∞) and thus group identities are overly fluid, the association between strategy and group membership breaks down. In our model, as in behavioral experiments9, this correlation between strategy and group membership is essential for the establishment and maintenance of in-group favoritism. Thus evolution cannot favor in-group cooperation if ϑ is too large. An intermediate set mutation rate is optimal, maintaining a delicate balance between mobility and consistency.

Our work generates testable predictions about evolved human behavior. For example, we find that a larger number of possible groups leads to stronger selection for in-group bias (Fig. 3b). This has implications both for laboratory experiments and field studies. Most existing laboratory experiments with economic games use binary groupings8,9, but our theory predicts stronger in-group bias if a richer set of groupings was used. Psychological research is consistent with this prediction52. Our results also suggest that people who developed their intuitions in more diverse communities, where a wider range of possible social groups exist, will demonstrate stronger in-group bias. Evaluating these predictions using quantitative empirical analysis is a promising research direction.

The framework we introduce here is not limited to the study of cooperation. It is a general theory for studying situations where one game is played with in-group members while another game is played with out-group members. For example, our framework can explain the evolution of costly in-group helping and costly out-group harming42 (see the online material). Applying this model to a variety of other social behaviors such as coordination, trust and bargaining51 is an important topic for future study, as is exploring situations where individuals are members of multiple groups with competing allegiances. Extending this framework to coalition formation53,54, which cannot always be reduced to pairwise interactions, will be useful.

In-group bias is a central aspect of human behavior1,2,3,4,5,6,7,8,9,25,44. This sensitivity to group membership may seem to imply a key role for inter-group conflict in human evolution. Yet, while inter-group conflict can promote the evolution of in-group bias20, to do so it requires stable groups whose membership remains largely unchanged over time. Contrary to this vision of stable groups, experiments8,25 and anthropological evidence40 have demonstrated that group identity and membership is often flexible. Over short timescales, the relevant grouping can be remodeled, leading to dramatic changes in behavior towards the same set of others. Here we show how in-group bias can evolve and thrive when group compositions are constantly shifting. It can be advantageous to love your friends, even when today's comrades might be tomorrow's enemies.