Image caption A sketch of a typical cell in the Miami jail

Imagine a jail where dangerous inmates awaiting trial live 24 to a room and fight each other under a violent gladiatorial code. This is life inside Miami's mega-jail, writes Louis Theroux.

For a bespectacled, peace-loving Englishman, there can be few places less congenial than a berth on the sixth floor of Miami main jail.

The place has to be seen to be believed. Up to 24 inmates are crowded into a single cell, living behind metal bars on steel bunks, sharing a single shower and two toilets.

Little of the bright Miami sun filters through the grilles on the windows. Visits to the yard happen twice a week for an hour. The rest of the time, inmates are holed up round the clock, eating, sleeping, and going slightly crazy.

But what is most shocking is the behaviour of the inmates themselves. For reasons that remain to some extent opaque - perhaps because of the bleak conditions they live in or because of insufficient supervision by officers, maybe because they lack other outlets for their energies, or because of their involvement with gangs on the outside, or maybe from a warped jailhouse tradition - the incarcerated here have created a brutal gladiatorial code of fighting.

They fight for respect, for food and snacks, or simply to pass the time.

With around 7,000 inmates, the Miami jail system is one of the biggest in America - a so-called "mega-jail". Most of these inmates are on remand - awaiting bail or being held until their trial dates - usually for fairly minor offences. In America, jails are distinct from prisons in that they hold people who are pre-trial and therefore unconvicted.

Most of these inmates reside at one of the two biggest facilities in the Miami jail system, large modern buildings where the cells are well-supervised and safe.

But the hardened few hundred who are either charged with particularly serious offences or have a track record of misbehaving behind bars get sent to the fifth and sixth floors of the main jail - a place with its own myth and lore.

Find out more The two-part documentary, Louis Theroux: Miami Mega-Jail, is broadcast on BBC Two on Sunday 22 and 29 May at 2100 BST Or catch up via iPlayer

Inmates throughout the jail speak with a sense of awe about the main jail, for it is here that the code of the jail is most stringently observed.

The idea of me spending time in the Miami jail grew out of a documentary I'd made about San Quentin in California in 2007. I'd been struck by the strange self-contained world of the prison - with its own rules and its own unexpected intimacies.

I'd come to Miami having heard that jails - with their more transient and therefore more chaotic population of new arrestees and defendants - were quite different, less settled and less domesticated. Inmates tended not to stay long enough to get comfortable or bond with officers or with each other.

Also, while prisons separate out their inmates so that the most serious cases are sent to "supermax" ultra-high security facilities, jails house the entire gamut of accused offenders.

Still, I was shocked by what I found.

Image caption Fighting is difficult to stop in the cells

A few days into my stay I arrived at the jail to find there had been a fight on the sixth floor - a man had been badly beaten by several of his cellmates. I visited the cell and was told by several inmates that the victim had been testifying on other people's cases. "Snitches get stitches," one said.

I tracked down the victim, who'd just arrived back from the clinic, his eyes swollen shut, looking as though he'd just gone 10 rounds with Vitali Klitschko. He said his cellmates had taken it in turns to fight him, one after another, six or seven in a row - a practice called "line-up".

Gingerly, I raised the possibility that he might have aroused the ire of his compadres by co-operating with the state on his case, maybe against his co-defendants? He said the idea was absurd - he'd been arrested for driving with a suspended licence.

A day or two later I met an inmate called Robert Tosta, a sturdy guy with an extensive track record of muggings and burglaries. Tosta was sporting a black eye and he explained that he'd been in a fight with a man in his cell.

Without privacy, sharing a single shower, many of the men had lost their sense of the normal social barriers

He'd noticed that some personal items were missing and, even though he had no idea who was responsible, jailhouse rules dictated that he had to ask his bunk-mate to "strap up" - put his shoes on for a fight.

In some cells inmates boasted that they had a policy of "mandatory rec" for new inmates - meaning any inmate coming into the cell had to fight (or "rec") for a bunk, unless he was known to other inmates in the cell, in which case he might be granted a reprieve.

And yet, strange as it is, fighting is far from being the only predatory behaviour that flourishes on the fifth and sixth floors of Main Jail.

Early in our visit, I heard whispers from the officers accompanying us that some of the inmates were being "disrespectful" during interviews. I was confused. They were shouting? Making faces?

No, they were "gunning" - that is to say masturbating - "at" and "to" our female director and assistant producer.

I recalled that some of the men behind bars had been swaddled in sheets as they stood or had lain covered on their beds - I'd assumed this was because they were camera shy - but in fact, it was explained, this was the better to hide.

Undoubtedly the practice was strange and uncomfortable for all the members of our team. And yet, even this I came to see as symptomatic of the strange conditions of the cells in the Main Jail. Deprived of any outside sensory stimulus they were hyper-alert to the sight of young women from the outside.

And without privacy, sharing a single shower, many of the men had lost their sense of the normal social barriers - they were around each other continuously, using the toilets, speaking to loved ones on the phone, and, presumably, indulging in other physical functions. And when we were around them, the same rules applied to us - many of them, living like animals, had lost their grip on social norms.

Up close and without the protective bars the men were actually less loud and less menacing

From the off I was keen to get inside the cells. The prison authorities do not usually allow this but we managed to get special permission and I ended up making several forays into the men's quarters.

Not surprisingly, having been told by the officers that for safety reasons it was "inadvisable" for me to enter a cell, I was somewhat nervous when I did so - chaperoned by a couple of officers, it must be said.

And yet, the first surprise was a sense that up close and without the protective bars the men were actually less loud and less menacing - they seemed nonplussed by my being among them and unsure of how to act.

There was an odd moment when one inmate, a young man named Shug, pulled his trousers down. But when I asked him what he thought he was doing, he seemed to think better of gunning and took part in the conversation.

Another inmate, Rodney Pearson, known as Hot Rod, told me he'd been inside for several years awaiting trial. Prosecutors wanted to give him the death penalty.

Image caption Some inmates are on remand for long periods

I asked him if, by some quirk of fate, I'd been arrested and sent to their cell, a bespectacled Englishman with a college education who was clearly not cut out to fight, they might let me off the "mandatory rec". The answer was an emphatic "no".

Horrible as it is, perhaps the biggest surprise in the main jail is that many of the inmates with the most serious charges choose to extend their stay as long as possible. Facing murder charges and prosecutors keen to give them life or even a death sentence, they figure that their odds of a better outcome at trial will improve the longer they wait, as witnesses die or disappear and memories fade.

It is a legal strategy known as "distancing". Some inmates had been inside for five years or more, still technically innocent, putting up with the most brutal conditions, for a chance of a better sentence.

Officers say there is little they can do to stamp out the fighting among inmates. They say it is the choice of the incarcerated men to participate in the code of the jail and that the inmate policy of no snitching means they can very rarely identify the chief culprits.

It is true that the layout of the jail - an old-fashioned design with a "walk" that runs past cage-like habitations that reminded me of nothing so much as a large multi-storey zoo - makes it difficult for officers to keep a constant watch on their charges.

One of the corporals said he thought the county might be happy to make reforms as long as I was happy to stump up the $600m for a new building.

Until then, he suggested, the strange code of the fifth and sixth floors will continue to hold sway.