Not far from you, ants are fighting for their freedom.

They have been victimised by "slave-maker" ants, which subjugate other ant species to do their work for them. To recruit slaves, the slave-makers deploy troops that conduct raids on surrounding colonies.

The system can be terrifyingly effective, in a sense akin to the horrific methods humans have used to keep slaves in line. The enslaved ants pay the ultimate price: they do not get to reproduce.

But the slave-makers do not get it all their own way. Some of their victims are fighting back. This battle is being fought, not just from day to day, but over evolutionary time – and nobody yet knows how it will end.

After mating, a slave-maker female does what any good ant mother would do: she finds a suitable place for her precious eggs and brood.

With an army at her beck and call, the queen goes about her business

But unlike other ants, she seeks a nest already occupied by another species. During summer, this nest will be chock-full of pupae getting ready to hatch into adult ants.

The ensuing battle feels like it has been taken straight from the most intrigue-ridden parts of human mythology. The slave-maker female systematically drives out or kills all the adult ants in the nest. Then she waits for the pupae to emerge.

For ants, like many other creatures, the smells and sights they encounter just after birth are crucial: they teach the baby ants what is "home". In this case, the chemical cocktails the newborns encounter cheat them into thinking that the slave-maker female is their queen. They become attached to her.

This is the first con.

With an army at her beck and call, the queen goes about her business. She lays her eggs, typically just one or two. The enslaved ants maintain the nest and take care of her brood.

When they hatch, the young slave-maker daughters have one task: to recruit more slaves. They start by scouting for other ants' nests nearby. Rather than attacking straight away, they head home and put together a raiding party.

They use chemical warfare

This group will contain some host ants. This is the second con: the enslaved hosts head out with the slave-maker workers and bring back more slaves.

The new slaves may well belong to the same species as the host. If the host nest split up after the initial attack, the slaves may force their own relatives into slavery.

If that wasn't fiendish enough, the slave-makers also sow confusion in the nests they attack. "They use chemical warfare," says Susanne Foitzik of the Johannes Gutenberg University Mainz in Germany.

Like all social insects, slave-maker ants have Dufour's glands, which secrete chemicals that the ants use to communicate. "They use the Dufour's gland to manipulate host defenders into attacking each other instead of fighting against the slave-maker," says Foitzik.

At this point it may sound like slave-making is a supremely effective way to live. But there are clearly limits to its effectiveness, because slavery is rare in the ant world.

It looks like slavery evolved independently in six different lineages

Among the approximately 15,000 known ant species, slave-making has been recorded in only 50. Only two of the 21 known subfamilies in ants have slave-maker species. Five different sub-groups of slave-maker ants belong to one relatively small group, the Formicoxenini.

That said, Foitzik thinks there might be more out there. In 2014 her team described a new American slave-maker species called Temnothorax pilagens. "We found it in Michigan, Vermont and New York, even though one would think that the ant fauna of the US is well studied."

What is more clear is that slave-makers can be very common, reaching densities of one slave-maker colony for every five host colonies, says Foitzik. Workers typically conduct about six raids each summer, each time killing adults and enslaving host pupae.

Based on the ant family tree, it looks like slavery evolved independently in six different lineages. But it's not clear how.

Slavery is a form of parasitism. The slave-making species are often completely dependent on their hosts, specifically on their hosts' group behaviour.

It is also ripe for picking by slave-makers

Many slave-makers are closely related to their host species, and they share chemical signals. That suggests that the common ancestor of both host and slave-maker was a species that got split into two groups. These groups did not mate with each other, forming two different species – one of which became the slave-makers.

Meanwhile, host species tend to form nests that are relatively dense and not well-defended.

For instance, Temnothorax hosts are common in temperate forests, with up to 10 nests per square metre – often in fragile sites like cavities in nuts and wood, or under stones. Each colony has only a few individuals, so it can split into many smaller nests with ease – but it is also ripe for picking by slave-makers.

Still, it is not easy for a female slave-maker to take over another nest.

Ants are social insects that live in large colonies. The ability to distinguish a nestmate from a foreigner is central to their very existence.

In a 2011 study, Tobias Pamminger and his colleagues at the Ludwig Maximilian University of Munich in Germany simulated a slave-maker raid. They kept nests of a host ant called Temnothorax longispinosus in the lab, and presented them with dead Protomognathus americanus slave-makers.

The potential hosts don't bother putting up a fight

After encountering the dead slave-makers, the Temnothorax hosts became extremely aggressive and the aggression lasted for three days.

They also became aggressive toward all ants that were not from their own nest. That may seem like an over-reaction, but any ant could be an enslaved member of the raiding slave-maker army, so it makes sense for the hosts to be hostile to all ants except those they live with.

Still, aggression may not always work, and the ants seem to know it. In areas where slave-makers are very common, Foitzik has found that the potential hosts don't bother putting up a fight. They just up and leave.

The ants are confronted with a "fight or flight" decision. When they feel aggression can overcome the slave-makers, they stick around; otherwise, they evacuate. Larger host nests are more likely to choose aggression, especially against small slave-maker raids.

When all else fails, and the nest ends up enslaved, the host ants have one last trick up their sleeve: mutiny.

Foitzik and her team noticed that colonies of the slave-maker ant T. americanus had lots of slave-maker larvae in spring, but come summer only a few adults popped out. That looked suspicious.

The team brought natural nests into their lab and studied how successful the host ants were at rearing their own brood and the slave-makers' brood.

Temnothorax hosts are able to recognise and kill slave-maker pupae

The enslaved Temnothorax workers did a fantastic job rearing their own pupae. On the other hand, they waited till the slave-maker brood pupated, and then systematically killed slave-maker pupae.

In about a third of cases, they jumped on the slave-maker pupae and tore them apart. The rest of the time, they removed the slave-maker pupae from their nest chamber and placed them outside, where they wasted away.

"It is [a] perfect example of a co-evolutionary arms race, with hosts developing defences and slave-makers finding new intriguing ways to exploit their hosts", says Foitzik.

It's a race that, in one way at least, the slaves appear to be winning.

Ants secrete special chemicals onto their outer cuticle. These chemicals act as identity badges and are also a way to communicate. As a result, Temnothorax hosts are able to recognise and kill slave-maker pupae.

It may be that the slave-makers will evolve into something more benign

In the chemical conversations between slave-makers and their hosts, the slave-makers often lie: they have evolved to give off the same chemical signature as their hosts. In this way they can trick the host workers into accepting the slave-maker pupae.

But they haven't got it perfectly right yet. In 2010, Foitzik's team showed that the chemical profiles of slave-maker and host pupae do not quite match. It seems that "the social parasite is running behind its hosts at least on the chemical side of this co-evolutionary arms race," they wrote. Even in nests that have never encountered slave-makers, the workers can pick out and kill the slave-maker pupae.

The worker ants that kill the slave-makers only get an indirect benefit. As workers, they will not be able to reproduce themselves, but Foitzik says they "will be helping their sisters residing in host colonies nearby, as these will be less often attacked."

This battle of disguise and recognition is a snapshot of evolution in action. Nobody knows how it will play out in the long run. It may be that the slave-makers will evolve into something more benign – or maybe the hosts will find a way to fight them off completely.