It's midnight on Monday and I'm standing in a dark cobbled street in Edinburgh's New Town, with a gaggle of other trepidacious theatre-goers. Beneath a flickering gas light, our guide gives us a brief history of the building in front of us. Mary's Chapel No 1, with its strange geometric squiggles on the lintel and shuttered windows, is, apparently, the oldest Masonic lodge in the world, with minutes dating back as far as 1599. Many of its rooms have never been open to the public before. Hushed with awe, we file in, up the mahogany staircase, down tartan-panelled corridors, past a stuffed fox, frozen mid-bark.
This is the setting for David Leddy's Sub Rosa, a gothic theatre piece set backstage in a Victorian music hall. For an hour and a half, we're led around dimly lit back rooms by an odd cast of characters before being ejected, thoroughly spooked, onto a rickety fire escape beneath the stars. The chill of the early morning Edinburgh air comes like a rude awakening from a very strange dream.
The next night, across town in Bristo Square, it's already well past midnight and a queue of young comedy fans clutching pints snakes around the concrete walls of the Pleasance Dome for The Horne Section. New to the Fringe this year, thisnicely shambolic show, hosted by Alex Horne (on French horn) combines a five-piece jazz band with a mixed bill of stand-ups. On the night I went, Josie Long demanded a sinister soundtrack for her take on Tory Britain ("When you leave the room, Michael Gove checks your text messages...") while Tim Key, who usually performs to a deliberately intrusive backing track, read poems off the back of a pack of cards to live jazz before performing a track by the Russian punk band Leningrad. A lightly tipsy crowd took part in audience battleships – the prize, a bag of chips, passed around the winning side of the room – and finally, at 2am, launched into a singalong of Bon Jovi's "Livin' on a Prayer", with Long on vocals and Mark Watson on drums.
For the month of August, at least, Edinburgh is the city that never sleeps. Performers, wired from their last show, carouse to the early hours. Audiences, overwhelmed by a roster of 2,500 shows, stay up as late as possible to cram them all in. There has always been plenty to cater for the reveller craving one last comedy hit before bed – traditionally, late-night mixed bills. The Underbelly has the occasionally titillating Spank! while the Gilded Balloon has Late 'n' Live, a sweary, sweaty lion's den of stand-up with beery heckling aplenty, which runs from 1am until dawn. For those who have overdosed on comedy, the sultry chanteuse Camille O'Sullivan can usually be found crooning in a darkened cabaret bar while itchy feet are catered for by club nights Silent Disco in the McEwan Hall or Guilty Pleasures in the Assembly at Princes Street Gardens.
This year, as Sub Rosa and The Horne Section demonstrate, there's a little more variety, even sophistication on offer. There are new takes on traditional stand-up, late-night theatre shows and book talks, candlelit concerts, bedtime stories and all-night arts clubs. All of them are taking advantage of Fringe-induced insomnia to experiment with genres and create new experiences for audiences hungry for round-the-clock entertainment.
Comedy still has the monopoly on the wee hours. This year, Tim Key reprised his award-winning show, The Slutcracker, for a midnight run, while Late Night Gimp Fight has been attracting buzz, and now an award nomination, for its deviant take on the traditional sketch show. The 11pm start allows the five-man troupe, who perform in bondage gear, to take some risqué risks with their material. The Five Pound Fringe regularly holds good-value guerrilla gigs at midnight at The GRV, announcing the performer and a secret entry code by text and Twitter just hours before. And new to the Fringe this year is the super-cool New York night Lach's Antihoot, an open-mic session of songs and jokes which launched the careers of Regina Spektor, Beck and The Moldy Peaches at its home in the East Village. Running til 3am, it's a lo-fi, good-natured antidote to the more aggressive Late 'n' Live, also at the Gilded Balloon.
Aside from these shows, there's been a mushrooming in late-night comedy experiments like The Horne Section, which offer opportunities to see stand-ups performing in an unusual context. Comedy in the Dark plunges them into a pitch-black auditorium, while Popcorn Comedy splices live performances (Sarah Millican, Cardinal Burns and Josie Long have all appeared this year) with screenings of the best comedy clips found online. Quirkier options are Comedy Countdown, an affectionate take on the television gameshow which pits comedians such as Mark Watson and Richard Herring against one another, with Paul Sinha in the Carol Vorderman role, and tom:foolery, a gin-soaked 1am Friday-night gathering of all the comedians at the Fringe called Tom – and there are many – hosted by The Penny Dreadfuls' Thom Tuck. Last week there was a power-cut at the GRV, so the gig, including Pappy's Tom Parry and Tom Allen, was held, impromptu, in the canteen at the Dome.
The beauty of these late-night gatherings lies in their unpredictability. Many only crop up for a few nights at the Fringe and the line-ups are announced late in the day. Audiences who take a chance and end up seeing a big name feel like they've been let in on a private joke while performers, in relaxed mode after performing their own shows earlier in the day, let loose with some of their funniest, freshest material.
Late night is the perfect time to seek out hot-off-the-press jokes, too. Crash Test Comedy, run by Idiots of Ants, is a new-material sketch night whose guests this year have included Frisky and Mannish, Delete the Banjax and Lady Garden, while Old Rope, run by Phil Nichol and Tiffany Stevenson, is a nightly dose of anarchy and just-written stand-up, which often welcomes big-name comedians who are passing through the Fringe and others who are keen to try out an untested 10 minutes. Last weekend Flight of the Conchords' Arj Barker dropped by with some brand-new material. As Stevenson says, "Thirty per cent of what you see tonight won't work, some of it might be rubbish, but it's about experimenting. This is the real spirit of the Fringe, right here."
The theatre programme, too, is extending its reach to the early hours. Sub Rosa is the best of the late-night plays, but Gutted, a bloody revenge musical at the Assembly Rooms, is also perfect midnight fare, featuring a host of comedians – Doc Brown, Sara Pascoe, Colin Hoult and the Penny Dreadfuls, to name but a few – moonlighting as singers and dancers. This year both the Pleasance and the Assembly Rooms have opened new venues with dedicated late-night cabaret programmes. Elsewhere, Les Enfants Terribles have brought their Rear Window-style thriller Ernest and the Pale Moon back to the Fringe in a 11.15pm slot (much more suitable than last year's teatime run) and the up-and-coming experimental theatre collective Belt Up are staging immersive plays around the clock in C venues. Their night-time offerings are Atrium and Quasimodo; after hours, the space becomes an all-night bar – part-speakeasy, part-house party, part-studio squat. In a similar vein is The Forest Fringe, an experimental hothouse open all hours, where you might stumble across the latest play from Kindle, Rotozaza or Little Bulb, take part in a spot of William Shatner Karaoke or simply hang out at one of their famous "performance parties".
That's not all. Classical music fans can end their day at Hot Chocolate, a series of candlelit concerts at 10pm in Old St Paul's Church off the Royal Mile. A haven for those battered and bruised by stand-up, this week's programme includes Schubert's Octet in F and The Calton Consort performing works by Britten and Schutz. A cup of devilishly rich hot chocolate from Chocolate Soup is included in the price. Another cosy option is Sarah Bennetto's cult Storytellers' Club. Taking over the ark at the Pleasance Courtyard every night between 10pm and midnight, the Fringe's more literary comedians gather around a fake fireplace and tell bedtime stories. Even the genteel Book Festival is staying up late this year with Unbound, a fantastic – and free – programme of events, running every night in the beautiful Spiegeltent from 9pm to 1am. So far there have been whisky-soaked nights with A L Kennedy, readings from up-and-coming Scottish writers, Canongate's Irregular literary club night and an evening with McSweeney's.
It's after hours that the Fringe, in all its unpredictable, experimental, occasionally messy glory, really takes flight. With five long nights of the festival still to go, there's a nocturnal event for every taste. Take a chance and a cup of coffee – who needs sleep anyway?