While most biologists would agree that humans are genetically inclined to behave altruistically towards immediate family, it’s more controversial to claim that humans are genetically inclined to behave altruistically towards their ethnic group, or race. Although part of the skepticism about the existence of ethnic loyalty stems from political correctness, much of it is scientifically legitimate. For if you sacrifice your life for your two children, the gene for family altruism will live on through them, since they each share 50% of your genes, but if you sacrifice your life for random members of your race, the gene for racial altruism will end with you assuming you are the first to have it. So how could ethnic/racial altruism evolve in the first place?
I think the answer to the paradox is that many ethnic groups originally started out as small families. All it would take is for a mother of a small family to have a gene that makes her sacrifice her life (if necessary) if she sees large numbers of people who look and act like her (relatively speaking) being seriously threatened by people who don’t look and act like her (relatively speaking). The degree of sacrifice she would make would be proportionate to the degree of threat and the number of people like her being threatened. Since most of her children and grandchildren and great grandchildren would have this gene, they would collectively form a tribe that would stick together in the face of threats from rival tribes which would give them a huge competitive advantage. Pretty soon their population would grow in size from a tribe, to an ethnic group. to an entire continental race.
Of course there would also be free loaders in the race that didn’t inherit the gene and thus benefited from the racial altruism without ever sacrificing for their group. What’s to stop such racial treason from being selected for? Well the people who had the gene for racial altruism would be especially hostile to any member of the race who wasn’t loyal, and they may even kill them and their children, so racial treason would not be adaptive. Even today we see that people who refuse to sacrifice in some way for their race are ridiculed as “Uncle Toms” and lose status within their ethnic group. In prehistoric times, a loss of status probably impaired genetic fitness.