Scientists have known for years that there is water inside the moon, but they now say they know where it comes from.

Researchers looked at samples taken from the Moon, crunched the numbers and found that water was delivered to the moon over a period of 10-200 million years by asteroids and comets.

The study suggests that the asteroids and comets crashed into magma oceans, which trapped water and prevented it from evaporating.

A paper in published in Nature Communications this week says most of the water inside the Moon came from asteroid collisions during the Moon’s early history, about 4.5 to 4.3 billion years ago.

The running theory is that the Moon was formed out of the debris generated by the collision of a Mars-sized planet with the Earth about 4.5 billion years ago.

In its early days, the Moon featured an ocean of magma on its surface and water insides, but until now, the timing and nature of the delivery of water to the Moon, and the relative contributions of asteroidal and cometary sources, have not been clear.

A team of UK, French and US researchers narrowed down the rate, source and timing of water delivery using a combination of numerical models. They also measured isotopic compositions of lunar samples from a range of previous studies.

They found that water was delivered to the interior of the Moon over about 200 million years, at a time when the lunar magma ocean was also present.

Based on hydrogen and nitrogen data from the samples, the authors show that a water-rich class of asteroids (known as carbonaceous chondrites) were responsible for most of the water in the lunar interior, with comets accounting for less than 20 per cent of the Moon’s total water holdings.

In this model, comets and asteroids collided with the magma ocean on the Moon, and a thermal lid — which formed at the surface of the magma ocean — prevented loss of volatiles such as water through degassing to space, allowing water to be retained in the Moon’s interior.

Although these results suggest that most of the water may have come from asteroids, the others note that some of it probably came from the early Earth during the Moon-forming impact event as well.

Lead authors of the new study have described their efforts in more detail in an article for The Conversation.