Deep within the hearts of Neptune and Uranus, it could be raining diamonds. Now, scientists have produced new experimental evidence showing how this could be possible.

The hypothesis goes that the intense heat and pressure thousands of kilometres below the surface of these ice giants should split apart hydrocarbon compounds, with the carbon compressing into diamond and sinking even deeper towards the planetary cores.

The new experiment used the SLAC National Accelerator Laboratory's Linac Coherent Light Source (LCLS) X-ray laser for the most precise measurements yet of how this 'diamond rain' process should occur - and found that carbon transitions directly into crystalline diamond.

"This research provides data on a phenomenon that is very difficult to model computationally: the 'miscibility' of two elements, or how they combine when mixed," explained plasma physicist Mike Dunne, director of the LCLS, and not listed as an author on the paper.

"Here they see how two elements separate, like getting mayonnaise to separate back into oil and vinegar."

Neptune and Uranus are the most poorly understood planets in the Solar System. They are prohibitively far - only a single space probe, Voyager 2, has even been close to them, and only for a flyby, not a dedicated long-term mission.

But ice giants are extremely common in the broader Milky Way - according to NASA, Neptune-like exoplanets are 10 times more prevalent than Jupiter-like exoplanets.

Understanding our Solar System's ice giants, therefore, is vital to understanding planets throughout the galaxy. And to understand them better, we need to know what happens underneath their serene blue exteriors.

We know that the atmospheres of Neptune and Uranus are primarily made up of hydrogen and helium, with a small amount of methane. Below these atmospheric layers, a superhot, superdense fluid of 'icy' materials such as water, methane, and ammonia wraps around the planet's core.

And calculations and experiments dating back decades have shown that, with sufficient pressure and temperature, methane can be broken down into diamonds - suggesting that diamonds can form within this hot, dense material.

A previous experiment at SLAC led by physicist Dominik Kraus at the Helmholtz-Zentrum Dresden-Rossendorf in Germany used X-ray diffraction to demonstrate it. Now Kraus and his team have taken their research a step further.

"We now have a very promising new approach based on X-ray scattering," Kraus said about their latest efforts. "Our experiments are delivering important model parameters where, before, we only had massive uncertainty. This will become ever more relevant the more exoplanets we discover."

It's challenging to replicate the interiors of giant planets here on Earth. You need some pretty intense equipment - that's the LCLS. And you need a material that replicates the stuff inside that giant planet. For this, the team used the hydrocarbon polystyrene (C8H8) in place of methane (CH4).

The first step is to heat and pressurise the material to replicate the conditions inside Neptune at a depth of around 10,000 kilometres (6,214 miles): pulses of optical laser generate shockwaves in the polystyrene, which heats the material up to around 5,000 Kelvin (4,727 degrees Celsius, or 8,540 degrees Fahrenheit). It also creates intense pressure.

"We produce about 1.5 million bars, that is equivalent to the pressure exerted by the weight of some 250 African elephants on the surface of a thumbnail," Kraus said.

In the previous experiment, X-ray diffraction was used to then probe the material. This works well for materials with crystalline structures, but less so with non-crystalline molecules, so the picture was incomplete. In the new experiment, the team used a different method, measuring how X-rays scattered off electrons in the polystyrene.

This allowed them not just to observe the conversion of carbon into diamond, but also what happens to the rest of the sample - it splits off into hydrogen. And there's pretty much no leftover carbon.

"In the case of the ice giants we now know that the carbon almost exclusively forms diamonds when it separates and does not take on a fluid transitional form," Kraus said.

This is important, because there's something really weird about Neptune. Its interior is way hotter than it should be; in fact, it gives off 2.6 times more energy than it absorbs from the Sun.

If diamonds - more dense than the material around them - are raining down into the planet's interior, they could be releasing gravitational energy, which is converted into heat generated by friction between the diamonds and the material around them.

This experiment suggests we don't have to find an alternative explanation… not yet, at any rate. And it also shows a method we could use to 'probe' the interiors of other planets in the Solar System.

"This technique will allow us to measure interesting processes that are otherwise difficult to recreate," Kraus said.

"For example, we'll be able to see how hydrogen and helium, elements found in the interior of gas giants like Jupiter and Saturn, mix and separate under these extreme conditions. It's a new way to study the evolutionary history of planets and planetary systems, as well as supporting experiments towards potential future forms of energy from fusion."

The research has been published in Nature Communications.