Studies of dolphins, primates and humans show the reason we choose the companions we do is more complex, and perhaps less honorable, than we might think.

“Friendship," wrote CS Lewis, “is born at that moment when one person says to another: ‘What! You, too? Thought I was the only one.’” He wasn't the only one. Plato wrote "similarity begets friendship" in his 360 BCE play Phaedrus. And Aristotle had the same idea when he wrote, "some define it as a matter of similarity; they say that we love those who are like ourselves."

Friendships blossoming on the basis of similar ideas, outlooks or tastes may seem intuitive, but that intuition is deceiving. Most friendships develop between people who are not family members or sexual partners, so friendship can't be explained on the basis of genetic or reproductive interests. Instead, evolutionary biologists have typically relied on a tit-for-tat process known as reciprocal altruism to explain friendship: you scratch my back, and I'll scratch yours.

The problem, however, is that social psychologists have discovered that people do not maintain mental ledgers of favours given and received. Primatologist Joan Silk described the riddle of friendship neatly: "reciprocity and equity are important among friends, but tit-for-tat reciprocity is antithetical to the formation and maintenance of close friendship. If these seemingly contradictory claims are correct, then friendship presents a puzzle for evolutionary analysis."

As with any evolutionary puzzle, it makes sense to look towards the animal kingdom for clues. Recently, a group of French shark scientists looked at whether aggregations among sharks could be explained in social terms – that is, if they were friendships – or whether sharks occupied the same space at the same time simply because of overlapping home ranges or mutual food sources.

The researchers focused their attention on 133 blacktip reef sharks, Carcharhinus melanopterus, a species known to patrol coral reefs in the Indian and Pacific Oceans. They learned that certain sharks preferred the company of certain others, and that those friendships persisted over time. And other pairs of sharks went out of their way to avoid each other, even if their territories overlapped. Geographic or territorial proximity is not enough to explain the riddle of their friendship.

Perhaps bigger-brained mammals like dolphins can help. Dolphin societies, like those of non-human primates such as chimpanzees, are characterized by two levels of social hierarchy: groups of two or three males, called "first-order alliances" work together to guard females from other males; and larger groupings comprised of several first-order alliances, appropriately referred to as "second-order alliances," cooperate to steal females from other groups. Typically, the individuals within first- and second-order alliances are related, so this sort of cooperation can be explained by shared genes, or kin selection.

Political creatures

But an Australian research team working in Shark Bay, Australia discovered, a third level of social hierarchy: coalitions among second-order alliances, which may be called "third-order alliances," or more imposingly as "second-order super-alliances," involving dolphins that were unrelated.

As with human friendships, the interactions among second-order super-alliances could not be explained by reciprocity. For example, a group of dolphins the researchers called PD prevailed over another group called KS in two separate occurrences. A social exchange-based theory of dolphin friendship would predict that PD and KS never cooperate. But that's exactly what the researchers saw when a third coalition, WC, attacked KS. To their amazement, PD swam into the fray to help their one-time nemesis defeat WC.

It turns out that dolphin friendships are not based solely on prior interactions, they are politically motivated. Cooperative decisions are based on who else is around at any given moment. Even if the PD and KS groups had historically been enemies, their mutual interest in defeating the WC group turned them into friends, at least temporarily. This seems to require an extraordinary amount of cognitive resources.

Political aspirations also seem to guide friendships among the male Assamese macaques Macaca assamensis, which are native to Thailand. For this social primate, dominance is the main factor that allows a male monkey access to females, and thus leads to reproductive success. In one study carried out in 2010, a monkey began ranking third in the group. Despite his relatively large size and good physical condition, he wasn't very good at making friends with the other male monkeys. It wasn't long before he tumbled to sixth position in the social hierarchy and lost his reproductive advantage. By the end of the observation period, he had fallen even further to eighth.

Could reputation protection – rather than similarity as Plato or Aristotle thought, or reciprocation as evolutionary biologists have argued – best explain the friendship riddle? In an experiment conducted by psychologists Peter DeScioli and Robert Kurzban in 2009, human participants created a list of their ten closest non-family friends, and ranked them according to closeness. They were then asked to imagine that they had one hundred points to distribute among those ten friends.

When the experiment participants were told that their distributions would be public knowledge, they doled out points fairly. Each friend received, on average, ten points. However, if the participants were told that their distributions would remain confidential, their allocations were less uniform. The best friend got the most points, followed by the second best friend, then the third, and so on. As social creatures with reputations to maintain, humans are acutely aware of the way that their behaviour might be viewed by others. So people rewarded their closest friends when they could get away with it, but strived to appear fair when under public scrutiny.

DiScioli and Kurzban use political examples to explain the complex nature of friendship, rather than simpler economic or geographic factors. They point out that despite the fact that the US traded with China over three times more than with the UK in 2006, the UK is far more likely to be described as a "friend" of America. They suggest that if "friendships are like international alliances, then friendship will not be well-explained by exchanges of benefits."

Friendships might serve as a strategic mechanism for maintaining a support system in advance of potential future conflicts. "Human conflicts are usually decided," they explain, "by the number of supporters mobilized on each side (rather than strength or agility)." So perhaps friendship only seems a riddle because if we were explicit about the transactional nature of our alliances, their strength would falter. In other words, we might like to make grand claims that friendships are without agenda, but that doesn’t necessarily mean this is the case.

If you would like to comment on this article or anything else you have seen on Future, head over to our Facebook page or message us on Twitter.