It is a question that has baffled scientists for decades.

With the sun’s atmosphere reaching temperatures of more than a million degrees, just why is it so hot?

Astronomers and physicists have spent years trying to solve the mystery and now the University of St Andrews has teamed up with NASA to finally provide an answer.

The ground-breaking research shows that magnetic field lines in the solar corona – the outermost part of the sun’s atmosphere – could hold the key.

Scientists found that the reconnection of these field lines results in bursts of energy, known as nanoflares and nanojets, which may account for the high temperatures.

Dr Paolo Pagano, of the University of St Andrew’s, explained how his team used computer simulations to better understand the process.

The scientist, from the university’s Solar and Magnetospheric Theory Group, said: “In St Andrews we focused on the explanation and modelling of the observed nanojets.

“Using state-of-the-art magnetohydrodynamic codes and high-performance computing infrastructures, we could reproduce the dynamics of the magnetic reconnection in the solar corona and the following nanojets with computer simulations.

“Our computer simulations describe in detail the dynamics of two misaligned magnetic field lines systems and how these undergo reconnection. As a result, a small energy burst occurs, the nanoflare, and the plasma is ejected sideways, the nanojet.

“For decades scientists have tried to demonstrate that nanoflares are behind the million-degree solar corona and to simulate these observed nanojets and heating in terms of the magnetic reconnection has been crucial in linking these observations to nanoflares.”

He added: “It should be emphasised that the solar corona is a very dynamic environment, where magnetic fields are continuously generated and disrupted releasing energy to maintain the million degrees corona as we explained in this work, but also triggering other phenomena, such as solar eruptions.

“Computer simulations have become an essential tool to understand the physics of the solar corona.”

The surface of the sun is covered in magnetic fields full of charged particles which form features known as ‘coronal loops’.

These loops connect to the Sun’s surface, keeping the magnetic lines constantly charged with energy.

Sometimes the field lines become tangled, then separate and reconnect in straight lines, creating the nanoflare energy burst and the subsequent nanojet – a burst of heated gas moving sideways very quickly between the two lines.

The research, published in Nature Astronomy, is the first to draw a link between magnetic reconnections and the sun’s temperature.

The scientists used data and footage from NASA to identify and analyse a ‘nanojet storm’ and the impact it had on the temperature of the corona.

Dr Patrick Antolin, of Northumbria University, who also took part in the study, said: “Misaligned magnetic field lines can break and reconnect, producing nanoflares in avalanche-like processes.

“However, no direct and unique observations of such nanoflares existed to date, and the lack of a smoking gun had cast doubt on the possibility of solving the coronal heating problem.

“From coordinated multi-band high-resolution observations we discovered evidence of very fast and explosive nanojets, the tell-tale signature of reconnection-based nanoflares resulting in coronal heating.

“Using state-of-the-art numerical simulations, we have demonstrated that the nanojet is a consequence of the slingshot effect from the magnetically tensed, curved magnetic field lines reconnecting at small angles.

“Nanojets are therefore the key signature to look for in order to see reconnection-based coronal heating in action.”

The storm observed by the team using the NASA footage lasted around 15 minutes. During that time the area of the corona being looked at went from being filled with cool plasma to heating up to millions of degrees.