We've all turned to melancholy music to make us feel better at some point in our lives, but why does doubling down on the sadness help drag us out of the mire?

A new study sheds light on what's going on inside our brains when we match our music to our feels, and it looks like sad music can be enjoyable - rather than simply depressing - because it triggers positive memories that can help to lift our mood.

The study – conducted by researchers at Durham University in the UK and the University of Jyväskylä in Finland – analysed three large-scale surveys, covering 2,436 people in total, and found that there was a wide spectrum of responses to wistful songs.

But three key responses stood out in particular: pleasure, comfort, and pain. Often these reactions were triggered by happy or sad memories recalled by the music, according to the researchers.

Psychologist Adrian North from Curtin University in Australia – who wasn't involved in the new study – says there are two groups of possible explanations for why we enjoy listening to sad music like this: one from social psychology, and one from cognitive neuroscience.

In terms of social psychology, one way of thinking about this is that we feel better about ourselves if we focus on someone who's doing even worse, a well-known process known as downward social comparison. Everything's going to be okay, because Thom Yorke is having an even worse day than you are.

Another hypothesis from social psychology is that people like to listen to music that mirrors the tone of their current life circumstances – the songs act as a sort of tuning fork for our own situations, and they resonate with us.

The second group of options, which North thinks is more convincing, is centred on neuroscience and the chemical processes actually going on inside our minds.

Some scientists think melancholy music is linked to the hormone prolactin, a chemical which helps to curb grief. The body is essentially preparing itself to adapt to a traumatic event, and when that event doesn't happen, the body is left with a pleasurable mix of opiates with nowhere else to go.

Thanks to brain scans, we know that listening to music releases dopamine – a neurotransmitter associated with food, sex, and drugs – at certain emotional peaks, and it's also possible that this is where we get the pleasure from listening to sad tunes.

Another hypothesis suggests sadness is handled differently by our minds when we experience it through art rather than first-hand: think a weepy movie, a poignant song, or a tragic painting.

Research published in 2014 showed that listeners often gravitate towards sad music because of its perceived beauty, and the greater aesthetic appeal of gloomy tunes was also noted in the new study from the UK and Finland.

That might link into the association between feeling miserable and creating iconic art: some research points to a melancholy temperament leading to works of art that are more appealing, to the extent that you can objectively judge art anyway. Arguably, sadness seems to make us more focussed and diligent, which could affect listening to as well as creating music.

One thing is certain: this pleasant sadness doesn't work the same way in everyone. The authors of the new study discovered that for some people sad tunes were in fact distressing and negative, usually because of the bad memories they brought up – so a somber and depressed soundtrack may not always be the best way to cheer up a friend.

The new findings have been published in PLOS ONE.