MOUNTAIN VIEW, Calif. – Somewhere in all of this, there must be a planet where the volcanoes spout chocolate.

Astronomers reported Monday that there could be as many as 40 billion habitable Earth-size planets in the galaxy, based on a new analysis of data from NASA’s Kepler spacecraft.

One of every five sun-like stars in the galaxy has a planet the size of Earth circling it in the Goldilocks zone – not too hot, not too cold – where surface temperatures should be compatible with liquid water, according to a herculean three-year calculation based on data from the Kepler spacecraft by Erik Petigura, a graduate student at the University of California, Berkeley.

Petigura’s analysis represents a major step toward the main goal of the Kepler mission, which was to measure what fraction of sun-like stars in the galaxy have Earth-size planets. Sometimes called eta-Earth, it is an important factor in the so-called Drake equation used to estimate the number of intelligent civilizations in the universe. Petigura’s paper, published Monday in the journal Proceedings of the National Academy of Science, puts another smiley face on a cosmos that has gotten increasingly friendly and fecund-looking over the last 20 years.

“It seems that the universe produces plentiful real estate for life that somehow resembles life on Earth,” Petigura said.

Over the last two decades, astronomers have logged more than 1,000 planets around other stars, so-called exoplanets, and Kepler, in its four years of life before being derailed by a mechanical pointing malfunction last May, has compiled a list of some 3,500 more candidates.

The new result could steer plans in the next few years and decades to find a twin of the Earth – Earth 2.0, in the argot – that is close enough to here to study.

The nearest such planet might be only 12 light-years away.

“Such a star would be visible to the naked eye,” Petigura said.

His result builds on a report earlier this year by David Charbonneau and Courtney Dressing of the Harvard-Smithsonian Center for Astrophysics, who found that about 15 percent of the smaller and more numerous stars known as red dwarfs have Earth-like planets in their habitable zones. Using slightly less conservative assumptions, Ravi Kopparapu from Pennsylvania State University found that half of all red dwarfs have such planets. Astronomers estimate that there are at least 200 billion stars of all types in the Milky Way galaxy, room for the imagination, and – who knows – perhaps for a few microbes or more complicated creatures to roam.

Geoffrey Marcy of the University of California, Berkeley, who supervised Petigura’s research and was a co-author of the paper along with Andrew Howard of the University of Hawaii, said: “This is the most important work I’ve ever been involved with. This is it. Are there inhabitable Earths out there?”

“I’m feeling a little tingly,” he said.

According to Petigura’s new calculation, the fraction of stars with Earth-like planets is 22 percent, plus or minus 8 percent, depending on exactly how you define the habitable zone.

Because there are probably hundreds of planets missed for every one found, the study did intricate extrapolations to come up with the 22 percent figure – a calculation that outside scientists say is fair.

“Everything they’ve done looks legitimate,” said MIT astronomer Sara Seager.

There are several caveats. Although these planets are Earth-size, nobody knows what their masses are and thus whether they are rocky like the Earth, or balls of ice or gas, let alone whether anything can, or does – or ever will – live on them.

There is reason to believe, from recent observations of other worlds, however, that at least some Earth-size planets, if not all of them, are indeed rocky. Last week, two groups of astronomers announced that an Earth-size planet named Kepler-78b that orbits its sun in 8.5 hours has the same density as the Earth, though it is too hot to support life.

Kepler was launched in 2009 to perform a kind of cosmic census, monitoring the brightness of 150,000 far-off stars in the Cygnus and Lyra constellations, looking for dips in brightness when planets pass in front of them.

Petigura and his colleagues restricted themselves to a subset of some 42,000 brighter and well-behaved stars. They found 603 planets, of which 10 were between one Earth and two Earths in diameter, and circled in what Petigura defined as the habitable zone, where they would receive between a quarter of the light the Earth gets, and four times as much. In our solar system, that zone would spread from inside the orbit of Venus to just outside the orbit of Mars.

Meanwhile, in an innovation borrowed from other data-intensive fields like particle physics, Petigura designed a computer pipeline so that he could inject fake planets into the data – 40,000 in all – and see how efficiently his program could detect planets of different sizes and orbits.

“It was a ton of work,” he recalled, explaining that he had to try out tens of billions of different periods for each star in order to find planets. “Fortunately, computers are cheap today.”

Seager, the outside expert, said the pipeline testing had made the results believable. “I would say that small planets are everywhere and very common – no matter how you slice and dice the data. But Kepler is dead and we have no way to get any further data. So we’ll have to be satisfied with this as the final word, for now.”