Musicians often find sleeplessness inspiring as well as tormenting. Matt Berry explains how he wrote his new album during nocturnal sessions, and Dave Bayley of Glass Animals says he owes his career to insomnia

Last year, the musician and actor Matt Berry found he couldn't get to sleep. He had experienced insomnia before, but this time was the worst yet. It started, as usual, with anxiety about getting enough rest before an important appointment. The worry kept him up so he watched a film to distract himself, then another, and then it was 3.30am and it was too late.

"Once you're past that stage then it's a nightmare," he says over a pint of orange juice in his local south London pub. Contrary to his expansive performances in The IT Crowd, Toast of London and House of Fools, he's a serious, thoughtful character. "I'd fall asleep at 4.30 and then I couldn't physically get up before 10 unless I had to. That isn't enough. I get into this bloody cycle where I'm so conscious of it that it's impossible to stop."

During the day he would be sluggish and clumsy, which made him frustrated. Each night, he would get more obsessed with getting to sleep on time, which of course ensured that he wouldn't. Eventually, he decided to go to the studio next to his bedroom and make some music. The result of these nocturnal sessions is his new album Music for Insomniacs. A low-key detour from the acid-folk of his previous solo albums, it is a mysteriously suggestive soundscape with hints of Brian Eno, Mike Oldfield and Jean Michel Jarre.

"I knew that this was dead time and I could be doing something instead of sitting worrying about not being asleep," says Berry. "That was important. I was despairing at the wasted time."

Dave Bayley, the frontman of Oxford art-pop quartet Glass Animals, owes his career in music to insomnia. He only started writing and recording because he had problems sleeping after leaving home to study medicine at King's College London in 2008.

"It was an inability to switch off my brain," says Bayley. "I was always working till quite late and it was hard to stop myself asking questions and thinking about things. Normally I'd fall asleep late and grab two or three hours, but sometimes I'd go back into the hospital with exactly zero sleep. I was pretty hazy. While I found it hard to sleep at night, I found it very easy to fall asleep in lectures or at the hospital, much to my supervisor's dismay."

Reading on mobile? Click here to watch the video.

According to the NHS, one in three Britons have episodes of insomnia in some form. Among several possible treatments, from basic "sleep hygiene" (such as avoiding caffeine and alcohol or wearing eye masks and earplugs) to cognitive behavioural therapy and sleeping pills, it recommends "calming music", but is no more specific than that.

There is much talk in the growing sleep industry about the soothing power of certain tempos, frequencies, keys and "delta binaural beats". A curious Berry consulted his friend, the actor and magician Andy Nyman, who called such pseudo-scientific claims "bullshit". Music is too personal. The music writer Sasha Geffen recently wrote about how Burial's remixes of Massive Attack "became a pill" guaranteed to send her to sleep, but she wouldn't suggest GPs start prescribing them.

In his own experimental listening, Berry found music was either too busy and hectic or so monotonous he was waiting for something to happen. "Those things are all in a key that is meant to stop you feeling negative, but it made me feel more negative because all I could see was the cynical execution. It seemed too obvious and artificial."

Bayley also found that his mind wandered while listening to ambient music, so he preferred more distracting records, especially Burial and Animal Collective. "It was music that made me feel I was in a different place – in a forest or a club – that helped me." He also tried other methods ("reading, sleep hygiene, watching terrible movies, going for runs") before making music for the first time. He slowly found his voice and eventually felt confident enough to play his work to the three friends who are now his bandmates.

"When you're sleep-deprived I imagine it's quite similar to having taken certain drugs," says Bayley, who has a degree in neuroscience. "The logical side of your brain is slowly withering away because there's not enough energy to power it, and all these crazy ideas start happening that your brain would normally suppress. I find the brain a mystical beast. It's so bizarre and interesting."

Berry had a similar experience in his studio, which has neither windows nor clocks. "It was kind of dreamlike. Sometimes I'd go back the next day and think: 'Wow. Some of it doesn't sound like me.' There are things I wouldn't have done during the day – lots of things coming in and out of focus."

Some studies have suggested a correlation between creativity and sleep disturbance, known as "creative insomnia", although this has been disputed. There is, however, plenty of anecdotal evidence from musicians. Artists such as Chris Martin, Moby, Tricky and King Krule have all talked about finding sleepless nights inspiring as well as tormenting.

Unusually, Berry set out to make music that might help other people alleviate their insomnia. He abandoned plans to theme it around childhood or being underwater because he didn't want to trigger unpleasant memories in certain listeners. "I tried to make it interesting but I've left it as blank as I can," he says. "I've used basic elements such as water and air. Other than that, it's whatever images you can conjure up from it. I'm not trying to push anything on you."

Glass Animals' mesmerising debut album Zaba wasn't made with insomnia in mind, but it was inspired by it. Bayley still works best in the quiet hours, free from distractions, which helps to explain Zaba's slippery, evocative ambience – the sense of music born in the shadows at the edge of coherent thought.

Reading on mobile? Click here to watch the video.

"Making music helped me get just enough sleep to manage, but after a couple of years I ended up wanting to make music so badly that it kept me up," he says. "All the main ideas for the album came at night. I'd not be able to get to sleep and some melody would creep into my head and I'd have to stay up recording, eventually collapse, get two hours' sleep, wake up in the morning and have the basis of a song."

Both men have found their bouts of insomnia have been relieved by the intensity of work, but both know it can come back. It is not something that you cure forever so much as learn to live with.

"I think not dwelling on it might be the key," says Berry. "When you can't think of anything else it takes over your day and you're lost from that moment. It won't rule my day ever again. I'm going to try to be in the driving seat."

"When my insomnia started I got so anxious, checking the clock every 15 minutes," says Bayley. "Eventually I just stopped caring. You lose the anxiety that is actually hindering you. Now if I can't sleep I get this peaceful excitement. I know I have time to try something out and have some fun."

• Music for Insomniacs by Matt Berry is out now on Acid Jazz. Zaba by Glass Animals is out on 9 June on Wolf Tone.