Twenty years ago this month, the rave scene reached its high point (or nadir, depending on your point of view) when thousands of people came together for the week-long Castlemorton Common Festival. Channel 4 is to celebrate this anniversary with a documentary, How Clubbing Changed The World, presented by the actor Idris Elba, and a six-hour danceathon featuring DJ sets from the likes of Grandmaster Flash and Annie Mac.

Rave's transformation of club culture turned it into a global force that influences just about every other pop genre. It has created a thriving branch of the entertainment industry and helped break down sexual and racial divides. Yet such an outcome would have been hard to predict when the authorities broke up Castlemorton, arresting a motley crew of crustie travellers and pilled-up ravers.

Since the late Eighties, police had been playing a cat-and-mouse game with party organisers and their followers, beginning with inner-city warehouse break-ins, then the M25 events outside London, before the mega-raves that culminated in Castlemorton. With drugs, trespassing and loud, amplified music, this was a subculture seemingly more pernicious than the previously demonised teddy boys, mods versus rockers and punk combined. It infuriated the establishment, especially the Conservative government that concocted the Criminal Justice and Public Order Act that infamously legislated against "repetitive beats". Yet those four-to-the-floor rhythms were not to be silenced. Instead, the scene went legit and occupied clubland.

Previously, nightclubs were shiny joints with cheesy names such as Fifth Avenue or Romeo And Juliet, where DJs worked more on their patter than their mixing. Any focus on tunes, sense of rhythm or technique was found in the underground scenes of gay, leftfield and black culture away from high-profile nightspots, some of which were starting to break down cultural barriers. In their authoritative tome Last Night A DJ Saved My Life, Bill Brewster and Frank Broughton chronicle a fragmented scene: soul boys, jazz funkateers, rare groove heads, electro poppers and the more open-minded environs of gay culture, chinks of light in a grim nightlife providing the building blocks for what was to come.

Some pioneers imported US DJing technology and techniques, while others relied on giving a premium to the latest dance moves or must-have tunes, earning passionate followings of obsessives happy to travel to far-flung suburbs or eccentric backwaters. Still, these groupings were contentedly elitist or struggled for space to express themselves. The black kids still faced forms of discrimination way beyond the institutional. Denied access to nightclubs, they were forced to take over disused buildings – instigating the first warehouse parties. Among them was another of the DJs set to perform on Channel 4, Jazzie B.

His Soul II Soul collective eventually gravitated to London's West End, moving into the Africa Centre for a series of legendary parties from 1986 to 1988 that shaped a distinctive UK sound combining soul and reggae. Even those Covent Garden parties were of dubious legality, but as Jazzie B explains: "London was a very different place in those days – there were different rules. Black youths couldn't get into clubs." Although technically operating on the wrong side of the law, Soul II Soul were proudly entrepreneurial, involved in both fashion and music. With figures such as Norman Jay, they attracted mixed crowds of trendies and thrill-seekers.

Raving took this mix of creativity, passion and communality and expanded it massively, thanks in part to ecstasy's chemical love-in. With disparate tribes gathering and UK music that was at last the equal of American imports, the business benefits were tangible. While the police clamped down on illegal raves, clubs welcomed a new clientele by adopting more flexible opening hours. New spaces were inspired by the stark interiors of the rave-hosting warehouses, perhaps most successfully London's Ministry of Sound. Door policies were relaxed, allowing an eclectic crowd to mingle.

Decent PAs became standard. combining the bass rumble of reggae sound systems with the high-definition of US set-ups. Fanzines became publications, dance labels burgeoned and record producers morphed into artists. House and techno dominated the charts and, beginning with Madchester, became a wider influence on guitar music. DJs became stars in their own right, earning eye-watering fees. Inevitably, the scene became bloated and the late Nineties saw a trend for more intimate nights at bars, while dance music fragmented.

Yet rather than facing a spectacular demise, as happened to disco at the end of the Seventies, club culture has continued to thrive as a worldwide success story, allowing new sounds to stake a claim on the dance floor. Still DJing and now presenting a show on BBC London, Jazzie B is sure things have changed for the better, thanks partly to the doors opened by illegal parties. "Everyone looks to Britain because we are a centre for youth culture. Now you find outdoor festivals and urban club culture all over the world. It's commercial and mainstream."

Even the US is taking notice. With its sounds adopted by R'*'B stars, electronic dance music has become entrenched in the States. Key has been the adoption of house rhythms by R'*'B stars, though now DJs themselves are earning mammoth fees to play huge outdoor parties. Raving has not only changed club culture, it is still at the heart of it.