Naturalists have long regarded ants and bees as a sort of living parable on the benefits of universal virtue. ‘Karl Marx was right, socialism works,’ said the great ant specialist Edward O Wilson; ‘it’s just that he had the wrong species.’ Certainly, the eusocial insects (from the Greek eu meaning ‘good’ or ‘real’) are better citizens than you or I will ever be. Reproduction is restricted to queens and drones. The workers, unable to pass on their private genome, devote themselves instead to the service of the nest. From the perspective of our own contentious societies, it’s tempting to view the anthill as a place of angelic (or robotic) order.

But that’s not quite right. Even in these superhumanly lawful communities, crime lurks. In virtually all the eusocial insects, a few workers surreptitiously lay eggs of their own, eggs that can grow into reproductive males. By diverting shared resources away from the nest, these workers selfishly reduce the fitness of their nestmates. They play the system for their own advantage.

In many species, including the Eurasian tree wasp, such unscrupulousness is held in check by a kind of policing behaviour. Wasps caught engaging in illicit reproduction are attacked. In tree wasps, rather intriguingly, the attack behaviour is performed exclusively by wasps who are themselves cheats. They are bigger and tougher than average, which comes in handy both in their police work and their criminal activities. In other species, however, the enforcers do not seem guilty of the same hypocrisy. Ordinary honeybee workers detect and devour more than 99 per cent of the eggs laid by their sisters. Among several species of ants, common workers will attack individuals whose ovaries indicate they might be reproducing, biting their limbs to the point where half of them die.

Such is the price of conformity. And these aren’t even the most thoroughly integrated societies in biology. Nature boasts collectives so harmonious that we rarely even think of them as such: collectives such as you, you great lumbering swarm of self-replicating cells. Your cells are astonishingly well-behaved. They fall on their molecular swords at the faintest whiff of selfishness. They rat on any neighbours they suspect might be harbouring revolutionary impulses, wafting out chemicals that alert the immune system. And yet, even here, rogue elements are known.

With enough mutations, cells can abandon the collective cause and set out on that doomed quest for self-actualisation we call cancer. To stop them, we have cellular cops – macrophages that monitor tissues and attack areas of unconstrained growth. And just like the ant police, these cellular enforcers can be suborned. Tumours sweet-talk young macrophages, recruiting them to join the rebellion. Instead of attacking the cancer cells, the macrophages grow excited, differentiating and multiplying. They start to secrete growth factors and defend the rogue growth from the rest of the immune system.

We are, in short, looking at a typical pattern in nature. A population organises itself around rules. It grants police powers to some of its members – and then those law‑enforcers use their privileges to cheat the system. Cliché has it that corruption is a cancer. The truth, though, is probably the other way around: corruption is the more general phenomenon, manifesting in one context as melanoma and in another as illicit reproduction – or police extortion.

But what if I were to tell you that it is not inevitable? That it can, to all intents and purposes, be eradicated from society? Would you believe me? And would you pay the price?

According to the non-governmental organisation Transparency International, each year around 16 per cent of the world’s (human) population bribes a police officer. That figure varies a good deal between regions, from just 0.5 per cent in Oceania in the Pacific Ocean to nearly 40 per cent in central Africa. Studies in Ohio and Illinois suggest that 70-80 per cent of police officers witness minor corruption each year. A 2002 police report claimed that corruption was so pervasive at Scotland Yard in the UK that crime syndicates could enter at will by bribing officers. In the US, investigations of police crime are said to be hampered by a ‘blue wall of silence’.

There’s a certain defeatism implicit in most approaches to these problems. While we see sporadic efforts to ‘clean up’ a particular department, organisation or neighbourhood, they tend not to be very systematic, and usually fall off after a year or two as public interest wanes. Perhaps our cynicism is justified. All too often, the very people who win power with promises to fight the rot are later found to be riddled with it. No wonder we collectively assign the problem to the global too-hard basket. But we shouldn’t be too hasty.

To defeat corruption, we need to understand why it arises in the first place. For that, we need game theory. A ‘game’ is a stylised scenario in which each player receives a pay‑off determined by the strategies chosen by all players. There’s also a variant of game theory that deals with so-called evolutionary games. In that kind of scenario, we imagine a population of self-reproducing strategies that get to multiply depending on the pay‑offs they achieve. A strategy is said to be ‘evolutionarily stable’ if, once it is widely adopted, no rival can spread by natural selection.

there is no possible strategy that can defeat the principle ‘always act like an untrusting jerk’

The archetypal co‑operation game is the Prisoner’s Dilemma. Imagine that two prisoners, each held in isolation, are given a chance to rat on the other. If only one takes the bait, he gets a reduced prison sentence while the other gets a longer one. But if both take it, neither gets a reduction. In other words, mutual co‑operation (saying nothing) provides a higher reward than mutual defection (ratting on your partner), but the best reward comes from defecting while your partner tries to co‑operate with you, while the lowest pay‑off comes from trying to co‑operate with your partner while he stabs you in the back.

The most obvious evolutionarily stable strategy in this game is simple: always defect. If your partner co‑operates, you exploit his naïveté, and if he defects, you will still do better than if you had co‑operated. So there is no possible strategy that can defeat the principle ‘always act like an untrusting jerk’.

At this point, you could be forgiven for thinking that game theory is both appalling and ridiculous. Co‑operation clearly pays off. Indeed, if you make normal people (ie people who are not economics students) play the Prisoner’s Dilemma, they almost never defect. And not just people. Rats will go out of their way to free a trapped cage-mate; rhesus monkeys will starve for days rather than shock a companion. Even bacteria are capable of supreme acts of altruism.

This trend toward biological niceness has been something of an embarrassment for biology. In fact, the task of finding ways around the more dismal conclusions of game theory has become a sub-disciplinary cottage industry. In the Prisoner’s Dilemma, for example, it turns out that when players are allowed to form relationships, co‑operators can beat defectors simply by avoiding them. That’s fine in small societies, but it leaves us with the problem of co‑operation in large groups, where interactions among strangers are inevitable.

Game theory (as well as common sense) tells us that policing can help. Just grant some individuals the power and inclination to punish defectors and the attractions of cheating immediately look less compelling. This is a good first pass at a solution: not for nothing do we find police-like entities among ants, bees, wasps, and within our own bodies. But that just leads us back to the problem of corruption. What happens if the police themselves become criminals, using their unusual powers for private profit? Who watches the watchers?

In 2010, two researchers at the University of Tennessee built a game-theoretical model to examine just this problem. The results, published by Francisco Úbeda and Edgar Duéñez-Guzmán in a paper called ‘Power and Corruption’, were, frankly, depressing. Nothing, they concluded, would stop corruption from dominating an evolving police system. Once it arose, it would remain stable under almost any circumstances. The only silver lining was that the bad police could still suppress defection in the rest of society. The result was a mixed population of gullible sheep and hypocritical overlords. Net wellbeing does end up somewhat higher than it would be if everyone acted entirely selfishly, but all in all you end up with a society rather like that of the tree wasps.

Is that where we live now? It can certainly seem that way. I grew up in Australia, which Transparency International lists as one of the least corrupt nations in the world. Even so, the local pizza shop delivered a pizza each week to the constabulary in gratitude for a certain forbearance. The US, according to published metrics, suffers minimal corruption, but who needs illegal corruption when the police can legally pull you over, ransack your car and sell anything they find? In Mexico, where one in five citizens has recently bribed a cop, an acquaintance recently paid several thousand dollars to persuade a pair of policemen to move out of her house.

In the original corruption model, the results left one tiny sliver of hope, a parameter region where corruption, though dominant, remained unstable. That observation suggested that, given a jolt, a society might transition away from the corrupt equilibrium. Intrigued by this, Duéñez-Guzmán and I decided to explore the model more deeply.

The results were startling. By making a few alterations to the composition of the justice system, corrupt societies could be made to transition to a state called ‘righteousness’. In righteous societies, police were not a separate, elite order. They were everybody. When virtually all of society stood ready to defend the common good, corruption didn’t pay.

social norms in hunter-gatherer societies are enforced by the whole group rather than any specially empowered individuals

Among honeybees and several ant species, this seems to be the status quo: all the workers police one another, making corruption an unappealing choice. In fact, the study showed that even if power inequalities later re-appeared, corruption would not return. The righteous community was extraordinarily stable.

Not all societies could make the transition. But those that did would reap the benefits of true, lasting harmony. An early tribe that made the transition to righteousness might out-compete more corrupt rivals, allowing righteousness to spread throughout the species. Such tribal selection is uncommon among animals other than eusocial insects, but many researchers think it could have played a role in human evolution. Hunter-gatherer societies commonly tend toward egalitarianism, with social norms enforced by the whole group rather than any specially empowered individuals.

Perhaps we can see something like human righteousness at work among the egalitarian Turkana of East Africa. The anthropologists Sarah Mathew and Robert Boyd of Arizona State University report that these 500,000-odd warlike nomads lack any kind of centralised political or military structure, yet they have maintained regional dominance for decades, raiding other ethnic groups at will. It’s a dangerous life: nearly a quarter of the men die in raids. What drives them to take such risks for the collective good? Not kinship, nor even friendship. They do not live in lasting tribes. Their settlements are loose and temporary. Most of the men participating in any given raid are strangers to one another.

Rather than personal ties, Turkana co‑operation seems to be maintained by a strong moral code, underpinned by the fear of egalitarian punishment. Turkana men were outraged by a hypothetical scenario in which one Turkana raided another; as Mathew and Boyd describe: ‘most subjects would not stand next to this warrior in a raid, entrust their herds with him, lend him a goat… or let their daughter marry him’. And this righteous attitude extends to performance in war. Battles are discussed at length after the event. Minor acts of cowardice result in mockery and scolding. In more serious cases, the culprit is tied to a tree and whipped by a group of his peers. Just desserts, in the community of the righteous. Is this what freedom from corruption looks like?

Game theory, of course, ignores the complexity of the human mind. We are all capable of behaving co‑operatively, righteously, corruptly and selfishly, all at the same time. Hardly anyone deliberately kills another person, for example, and in the absence of extenuating circumstances, most of us would turn in our friends for doing so. It would appear that we’re already righteous about murder.

Attitudes to infidelity present an intriguing contrast. Most people agree that it is wrong, yet we generally turn a blind eye to our adulterous friends. Meanwhile almost everyone drives too fast and downloads popular TV shows without paying for them. Such quiet cheating is likewise evident among egalitarian hunter-gatherers. ‘It would be a rare Mbuti woman who did not conceal a portion of the catch in case she was forced to share with others,’ noted the anthropologist Colin Turnbull in Wayward Servants: The Two Worlds of the African Pygmies (1965).

Those differences in attitudes might seem appropriate to the severity of the crimes. And yet murder is far from being the only topic we get righteous about. We can be blithely judgmental of other people’s fashion choices, personal hygiene and manners. We seem to revel in generating and enforcing arbitrary social rules, from Catholic confession to the ritual nose-bleeding of Sambia men in Papua New Guinea. Granted, our punishments for minor infringements are usually subtle: a joke, a snub, a verbal rebuke. But don’t underestimate their impact. Repeat offenders are likely to find themselves gradually ostracised, mateless and unsupported in times of need. Evolutionarily speaking, social rejection might as well be a death sentence for humans.

the powerful cheated more on a game of dice, and then readily forgave themselves

And this is not the full extent of our moral flexibility. Even as we ruthlessly enforce our codes, we try to cheat them. Lord Acton claimed in 1887 that ‘power tends to corrupt, and absolute power corrupts absolutely’, and the evidence supports him. In a 2010 study, the researchers Joris Lammers at the University of Cologne and Adam Galinsky at Columbia Business School primed their subjects to feel either powerful or powerless. Those who felt powerful condemned others’ hypothetical immoral behaviour more harshly than those who felt powerless. But at the same time, the powerful cheated more on a game of dice, and then readily forgave themselves.

Such hypocrisy makes sense from an evolutionary perspective. As the Rutgers biologist Robert Trivers put it in Deceit and Self-Deception (2011), we evolved to fool ourselves so we could better fool others. Righteousness is a sound strategy for the young revolutionary surrounded by righteous peers. On the road to power, you need allies who must be convinced of your sincerity. But once you have cemented your position, you can most improve your fitness with covert acts of selfishness, justified by a new-found sense of entitlement.

We would appear to have found our mechanism. Our tendency towards righteousness might be triggered when we feel equal to our potentially righteous compatriots; and the more secure we feel in our power over them, the more we switch to corruption. Can we use social engineering to manipulate this switch? The model suggests that we can. If we decrease power inequalities, increase punishments and reward punishers, in theory that should trigger a societal transition to righteousness.

Here’s how it might look in practice. Imagine a city where police commit blatant traffic violations and never ticket one another. The authorities could decrease power inequalities by developing an online system in which all citizens are able to anonymously report dangerous drivers. Anyone who received too many independent reports would be investigated – police included. This sounds almost laughably simple, and yet the model indicates that it ought to do the trick. It is, after all, essentially the same system used by many online communities.

Indeed, if anything, such systems might work a little too well. A punitive review on Yelp can devastate a young business. While uncensored communities are quickly overrun with trolls, communities that upvote good behaviour and sternly punish mischief can become stiflingly polite, awash with unique cultural norms, private in‑jokes and abstruse discussions of the code of conduct. Behaviour that garners upvotes on Reddit will see you banned on Quora. As a species, we appear to have an insatiable appetite for enforcing arbitrary norms.

Imagine, if you will, a society where the laser eye of social condemnation is trained on every possible transgression. Safely rolling past a Stop sign earns the same disgust from your friends as if you were to pick your nose at the dinner table. Listening to a pirated MP3 of your favourite song would shame your whole family, and your spouse would divorce you for sharing a sip of wine with your 17-year-old son. There can’t be many people for whom this sounds like an appealing vision.

Then again, if we can be righteous when it comes to fashion yet corrupt when it comes to adultery, is it implausible that we might be disgusted by bribery yet tolerate other small acts of rebellion? Already, most of us participate in numerous different social contexts, switching adeptly between roles and social norms.

Armed with game theory and a wealth of social data, it seems we have – for the first time in history – the tools to start experimenting with democratic, egalitarian social structures that bring out the best in us. We would, of course, have to proceed with caution. As early as the 18th century, the economist Bernard Mandeville envisaged a transition to perfect, peer-enforced co‑operation – and argued that it could only end in disaster. In his book The Fable of the Bees (1714), he depicted a society where prosperity and progress derive from endless conflict over ubiquitous corruption:

Thus Vice nursed Ingenuity, Which join’d with Time, and Industry Had carry’d Life’s Conveniencies, It’s real Pleasures, Comforts, Ease, To such a Height, the very Poor Lived better than the Rich before

Jove, in a fit of irony, curses the bees with honesty. Their wealth promptly dissolves, society stagnates, and the population dwindles as the virtuous bees are unable so much as to contemplate any sort of creative rebellion. Sometimes it’s good to bend the rules. But which ones?