On visiting days, the general penitentiary of Venezuela looks more gangster's paradise than penal institution: along the main corridor, rows of tables display cocaine, ecstasy, pot and crack in precisely arranged quantities.

Heavily armed prisoners and their girlfriends swagger, laugh and dance as reggaeton blares from giant speakers. There is a pool hall, internet cafe, air-conditioned gym and disco – all provided thanks to the largesse of a former prisoner. There is not a guard in sight.

Such bacchanalian scenes have prompted some to dub this the Beverly Hills of prisons, but the nickname is dangerously misleading. This jail near the capital, Caracas, is at the heart of a chronically overcrowded, corrupt and murderous prison system that ranks among the worst in the world.

Last month, the army was sent to one of Venezuela's biggest jails, Uribana, to search for drugs and weapons. The prisoners fought back in a two-day battle that left 58 dead and more than 100 injured. Human rights groups say more than 500 prisoners were killed last year and 600 in 2011.

"Being sent to a Venezuelan jail is like being buried in a cemetery for the barely alive. It's a living hell," said "El Varón", a visitor who once served seven years in jail. "You know when you go in, but you never know when or how you'll come out."

Justice is not just slow and contentious – it is almost absent. Instead, the prisoners make their own rules and set their own territory, according to the principle of survival of the strongest.

For the prisoners at the general penitentiary, in San Juan de los Morros, 55 miles south of Caracas, that means jail can seem like a surreal, hedonistic pleasure palace, or the cruellest hellhole. It depends what side of the jail they are in.

Divided from the main hallways by a pockmarked wall is an area designated by prison leaders – who are known as "prans" – for those prisoners judged too unruly to abide by unwritten prison codes. In this "jail within a jail", the music is barely audible and no one is in the mood to party. Emaciated men live on top of one other in makeshift hammocks made of tattered sheets. Many cough – the result of a TB epidemic that goes largely unreported and untreated. Walls are riddled with bullet holes and the stench of sewage mixes with the scent of marijuana.

Most men here do nothing but wait out a sentence that has yet to arrive. Human rights activists say almost 70% of inmates are being held in pre-trial detention. Some do odd jobs, such as fixing broken air-conditioners or painting the walls of the main prison. Their wages – paid by the pran – finance their drug habits.

"We have to separate the worldly men from those who stain the republic," said Leo, a pran, referring to the strict hierarchy the prisoners have established.

That prisons are controlled by heavily armed inmates does not surprise human rights activists. A standoff in 2011 at El Rodeo prison outside Caracas revealed that the prisoners had more than 12kg of cocaine and marijuana and an arsenal of military grade weapons that allowed them to resist a month-long siege by the national guard.

For Carlos Nieto Palma, the director of Window to Liberty, a prisons monitoring group, said the most recent conflict at Uribana prison again shows that the government has lost all authority over its prison system.

"When you have a minister of penitentiary affairs who has been repeatedly denied access inside Uribana it is clear that prisons are controlled by inmates, and not the state," Palma said.

There is also evidence that jails have become centres for organised crime. Media reports have told how jailed gang leaders plot kidnappings, murders and oversee drug-trafficking operations.

The media estimate that each prison averages a gross profit of $2.5m (£1.55m) a year through criminal activities and weekly taxes, or causas, levied on prisoners.

But Palma believes the crux of the problem lies not within prisons but in poor administrative and legal deficiencies that plague the justice system.

"The real pran is the one outside – the national guard or the penitentiary official – that sells the weapons to the inmates or allows the drugs inside and gives permission to the weekend parties with strippers that we hear about. They have to have a pran inside because that is part of the business," Palma said.