I'd say it's mostly learned. Some of it is innate because of our innate tendency to learn empathy but to me it seems learned. We have quite strong innate tendencies toward ingroup-outgroup separation and competitiveness. You need not go further than a schoolyard to observe those tendencies in action. Moreover, identities shared between large groups of people tend to be the result of conscious effort. Things like language standardization, religious and ideological propaganda, and conflicts in opposition to common enemies help consolidate ingroup membership recognition among strangers belonging to large groups. National and religious identities for large numbers of people take a long time and much effort to build.
It used to be unquestioned that human cooperation was instinctual because humans are social animals. However, recent research suggests that cooperation is actually a learned process and that humans can adapt to new rules based on how much cooperation there is a society.