Ingroup favoritism, the tendency to favor ingroup over out-group, is often explained as a product of intergroup conflict, orcorrelations between group tags and behavior. Such accountsassume that group membership is meaningful, whereas humandata show that ingroup favoritism occurs even when it confersno advantage and groups are transparently arbitrary. Anotherpossibility is that ingroup favoritism arises due to perceptualbiases like outgroup homogeneity, the tendency for humans tohave greater difficulty distinguishing outgroup members thaningroup ones. We present a prisoner’s dilemma model, whereindividuals use Bayesian inference to learn how likely oth-ers are to cooperate, and then act rationally to maximize ex-pected utility. We show that, when such individuals exhibitoutgroup homogeneity bias, ingroup favoritism between arbi-trary groups arises through direct reciprocity. However, thisoutcome may be mitigated by: (1) raising the benefits of coop-eration, (2) increasing population diversity, and (3) imposing amore restrictive social structure.