The skies over Rio de Janeiro are packed with creatures and machines of all shapes and sizes. Huge gaviotas, the piratical frigatebirds with pterodactyl-like silhouettes, scan for smaller birds to assault and rob of their meals. Other species strike out here and there in noble V-formations, or swarm chaotically over patches of jungle. For Rio's humans, it's one of the ironies of life that the best picture-postcard views of the city belong to some of its poorest residents, the hillsides being the typical sites of the shantytown slums, the favelas. "Hill", here, is actually a byword for favela. But from the air, among the mountains, above the beaches and the glittering sea, the views are good too. And so people are airborne in any hang-glider or parachute they can get their hands on. Trembling propeller planes make their rounds, insecurely offering their advertisement banners to beachgoers as an alternative to the horizon. And there is always a helicopter overhead. The red ones shimmy about above the water, dropping rescuers and baskets, saving people from waves that feel as though they could drown you with just their after-froth. The blue helicopters belong to the world's deadliest police force. They can be seen sometimes in tight pairs, in low, doors open, carrying men with machine guns.

And now there is a new presence in these skies, circling somewhere high above the rest: an Israeli-made Heron reconnaissance drone, one of an initial three purchased last October as part of a drive to improve public security in the run-up to the World Cup in 2014 and the Olympics in 2016. "Only with a war weapon, such as a land-air missile or cannon, could the traffickers shoot down the aircraft," announced Alessandro Moretti of the Federal Police at the time.

The focus on whether or not the traffickers would be able to down the new drone was dictated by what had taken place earlier that month: a Military Police helicopter had been shot down during a two-day war between drug gangs in the Morro dos Macacos favela. The Commando Vermelho ("Red Command"), the largest of Rio's three mafias, had invaded territory belonging to the Amigos dos Amigos ("Friends of Friends"). Several buses were torched and at least 15 people killed in the ensuing violence, including three of the policemen on board the helicopter. One person was arrested. Even though it was small arms fire that had brought down the helicopter, Moretti's claim was hubristic: "war weapons" are exactly what the traffickers have, and escalation is the order of the day. Many favela residents will tell you that they've seen missile launchers and bazookas in the hands of the gangs, and in the police operations that followed from this very war, two 30mm anti-aircraft guns were recovered, along with a handful of imitation police uniforms and other worrying items.

Rocinha, home to about 200,000 people and thought to be Latin America's largest slum (Getty Images)

The first favelas appeared in Rio towards the end of the 19th century in the form of quilombos, settlements of escaped African slaves. These were augmented after the emancipation of slaves in 1888, and in 1897, 20,000 soldiers arrived in Rio, fresh from the War of Canudos, a bloody conflict between the government and a rebel colony of ex-slaves and other disenfranchised peoples in the north-eastern state of Bahia. The soldiers found that they had no option but to establish squatter settlements themselves. Through the middle of the 20th century, massive migrations from Brazil's rural interior continued to swell the favelas, and it is concisely indicative of the legitimate society's traditional attitude to these communities that no one now seems to know how many favelas there are in Rio. The 2000 census counted 513. There are usually estimated to be more than 1,000 now, housing about two million people — "more or less", mais ou menos in Portuguese, is an extremely common phrase here. It could be 1.5 million, it could be three million.

In the early 1980s, the drug traffickers began to fill the power vacuum created by the state's absence. For the vast majority of the residents of Rio's favelas, life has been lived since that time according to the strict rules of this one or two per cent minority of heavily armed criminals. The phenomenon has a Marxist heritage, as suggested by "Red Command", the name of the oldest gang from which the others were later spawned. But any political motivation fell away almost immediately. It is a strictly capitalist venture, selling cocaine and marijuana to the rest of Rio's inhabitants in a trade worth millions of US dollars a month. The bosses still like to think of themselves as Robin Hood figures, and they provide some basic services, ad hoc assistance and occasional treats for the people they control. On a Sunday evening in Rocinha, home to some 200,000 people and thought to be Latin America's largest slum, I found the street blocked at intersections by bouncy castles and trampolines laid on by the Amigos dos Amigos. Children were queuing up, in orderly single-file but already bobbing up and down, oscillating with growing energy as they drew nearer to the frenzied play.