Of the 7 billion people on the planet, only 530 have been in orbit, and less than half of those have ever physically been outside a module, walking and working and floating in space.

No film in recent memory has sparked as much terror and fascination with the idea as “Gravity,” starring Sandra Bullock as an astronaut who becomes untethered from her space station, possibly lost forever.

It’s the fate every astronaut dreads: To quote Col. Chris Hadfield, author of the new memoir “An Astronaut’s Guide to Life on Earth” (Little, Brown), “My number one concern . . . is to avoid floating off into space.”

Next on that list: avoiding fatal mechanical defects during launch, fire in the spacecraft, an astronaut becoming gravely ill or dying while in orbit, loss of communication with ground control, a calamitous event occurring back on Earth while you exist beyond the bounds of the planet, and burning up upon re-entry.

Other than that, Hadfield says, it’s the most magical experience a human being could ever have.

‘I’VE ONLY GOT A COUPLE MORE MINUTES TO LIVE’

Hadfield, a Canadian, became an astronaut in 1992 and says he’s never encountered anyone who doesn’t regard it “as a job full of dreams.” He first flew in space in 1995, but it wasn’t until his second mission, in April 2001, that he left the ship and walked in space.

He is a genius, a man of science and technology and no first-timer to the universe. “Intellectually, I’d known I was venturing out into space,” he writes, “yet still the sight of it shocked me, profoundly.”

He describes the primal awe and fear of pushing out into the void: “How is this possible?” he writes. “What’s coming out of my mouth is a single word: ‘Wow.’ It’s like being engrossed in cleaning a pane of glass, then you look over your shoulder and realize you’re hanging off the side of the Empire State Building, Manhattan sprawled vividly beneath and around you.”

Until that moment, Hadfield writes, he had never truly experienced space. Now, here he suddenly was, attached to a spaceship orbiting the Earth at 17,500 miles an hour, tasked with helping to install a robotic arm on the International Space Station. His training kicks in, and with extraordinary mental discipline, he redirects his attention away from “the astonishing beauty of our planet, the black velvet bucket of space brimming with stars,” and gets to work.

During this task — a project planned and executed in years-long simulations back on Earth — Hadfield will tear up, and it will nearly kill him.

Hadfield is out in space for five hours with fellow astronaut Scott Parazynski when it begins. He is attached to the ISS with a tether, his feet secured in restraints, working a drill when his left eye begins to burn so badly that he reflexively brings up a hand to rub it, smacking his helmet.

Since Hadfield can still see out of his right eye, he says nothing to ground control: He does not want to leave outer space. And for all his training, nothing can prepare him for the real-time realizations he is having: Oh, right, yes, there’s no gravity in space, and so his tears aren’t going to fall. They are building and building on the surface of his eye, creating a swampy mess that is blinding him.

And now they are migrating over to his right eye, both so clouded and burning that he can’t stop himself from shutting them both. “In the space of just a few minutes,” he writes, “I’ve gone from 20/20 vision to blind. In space. Holding a drill.”

Hadfield has no choice and utters those famous words: “Houston, I have a problem.”

His fellow astronaut is still working away, deliberately displaying no distress, while Hadfield tries to take advantage of his closed eyes: He imagines he’s back on Earth, in his home, in his bed, under the covers, the closest he could get to being back in the womb — the exact opposite of the gaping, limitless void that has no regard for his fate.

He can hear the frantic whispering among the scientists at CAPCOM; every time they ask him a question, they need to consult among themselves before giving him an answer or an instruction, which means that no one in the history of space travel has ever experienced this before.

The diagnosis, reached in less than five minutes: Hadfield’s spacesuit is contaminated with lithium hydroxide, which is used to eliminate carbon dioxide. That Hadfield’s eyes are so inflamed means there’s likely a leak.

“I’ve only got a couple more minutes to live,” he writes.

Ground control tells him he must open his air valve — essentially, expose himself to space — to try and disperse the contaminant. He has to force himself: It runs counter to his primal survival instinct, having to expel his own air supply into outer space.

“So now I’m blind, listening to a hissing noise as my oxygen merrily bubbles out into the universe,” he writes.

It works. Hadfield is overjoyed to still be out there, and gets right back to work installing the arm.

SPACE ODDITIES

Though the images we see of astronauts in space look graceful and effortless — the balletic effects of zero gravity — Hadfield compares spacewalking to “rock-climbing, weightlifting, repairing a small engine and performing an intricate pas de deux — simultaneously, while encased in a bulky suit that’s scraping your knuckles, fingertips and collarbone raw . . . Just turning a wrench to loosen a bolt can be like trying to change a tire while wearing ice skates and goalie mitts.”

Hadfield spent years training to spacewalk in a giant pool at the Neutral Buoyancy Lab, where he executed every conceivable action he would be tasked with in space. The most basic and valuable aspect of the training is learning how to overcome fear — Hadfield himself is afraid of heights — and, upon the completion of any job or the solving of a problem, to immediately ask yourself: What’s the next thing that could kill me?

And just like Earth-bound aviation, the most dangerous parts of the flight are the takeoff (launch) and landing (re-entry). Once you’re up there, you’re probably OK.

Hadfield’s third and last trip to space, in December 2012, would be his longest: nearly four months, living and working on the ISS. A rocket can reach it from Earth in under three hours, but Hadfield and his two-man crew — who were rendezvousing with two cosmonauts and one astronaut already on board — took a day, which allowed them to rest and adjust to zero gravity.

The wonder, he writes, never ceased: He was never not stupefied to be looking down at this giant blue marble and gazing at the Nile River, or the Sahara Desert, or the Great Wall. He has never seen a UFO, but believes we are not alone: “It seems mathematically improbable, given the size of the universe.”

His greatest regret was that he required sleep.

He writes of the wonders and worries of being in space for so long: There is no running water on the ISS; it’s too dangerous in zero gravity, so they recycle their own sweat and urine and drink that, and as repulsive as it sounds, Hadfield reports it’s cleaner than the stuff that comes out of our own taps.

Astronauts must ingest their toothpaste and clean themselves with sanitized wipes, but it’s largely fine because no one smells in space; Hadfield thinks it’s because clothes never really touch the skin. Astronauts also must exercise for two hours a day lest their muscles atrophy. Everything from nail clippings to stray hairs must be captured and vacuum-sealed, and they must pee into a funnel, which is never easy and always, always requires cleanup; one astronaut posted a sign reading, “Blessed are those who clean the funnel.”

THE STUFF OF DREAMS

Weightlessness, Hadfield writes, is a constant source of amazement, no matter how long you’re up there: It allows you to push a piece of car-sized machinery with your fingertip, to literally fly. But there are deleterious physical effects to living in space long term: Your heart shrinks, you lose bone mass and muscle, eyesight gets worse, and the immune system loses strength. Astronauts monitor every change they undergo, and the results are used in everything from Earth-bound medical and technological research to planning for a manned trip to Mars.

Hadfield and his fellow travelers remained deeply connected to Earth; they had the Internet and communicated with their families via phone and e-mail. Hadfield writes that they followed the Boston Marathon bombings in real time.

Hadfield began posting pictures and tweeting from space, conducting exchanges with William Shatner. An amateur musician, he recorded songs and posted them to YouTube, and David Bowie granted him permission to perform and post a cover of “Space Oddity.” On May 12 of this year — just before he was about to return home — he recorded and posted it to YouTube, where it racked up 10 million hits in three days.

In the version Hadfield sang, Major Tom survives. Hadfield calls himself an eternal optimist and says the millions of miles and thousands and hours he has logged in space have only made him feel more connected to his fellow man, and to humanity’s desire to push ever forward.

“Even the least eventful day in space,” Hadfield writes, “is the stuff of dreams.”