A view of the toilet compartment in the Zvezda Service Module of the International Space Station (ISS).

On May 5, 1961, NASA astronaut Alan Shepard was locked into his capsule Freedom 7, ready to become the first American and second person ever in space. But before his 15-minute historic flight, Shepard would sit through five hours of delays — and he really had to go to the bathroom.

"Man, I got to pee," he radioed launch control.

NASA officials weren't prepared for this situation. They thought the mission would be short enough to avoid it, and letting Alan Shepard urinate in his shiny silver spacesuit was not something they were ready to do; the astronaut was wired with medical sensors that might get wrecked if wet. But eventually, launch control had no choice but to let him to go.

Mark Roberts, a tour guide at the Intrepid Air & Space Museum in New York, gives a talk about going to the bathroom in space on July 25, 2013, during SpaceFest. The picture he is pointing to on the screen shows a NASA engineer modestly demonstrating how an Apollo fecal collection bag works over a pair of plaid pants. (Image credit: Megan Gannon/SPACE.com)

"You think it's glamorous being an astronaut? It's a lot of hard work and a lot of indignity as well," Mark Roberts, a tour guide at the Intrepid Sea, Air & Space Museum in New York City, said during the museum's recent summer SpaceFest last month. [Space Toilet Technique: NASA's How-To Guide (Video)]

After Shepard's debacle, NASA devised better ways to take care of basic bodily functions. But space waste continued the plague the agency.

By the time astronaut Gordon Cooper launched on the last Project Mercury flight in 1963, NASA had created a urine collection device that astronauts could wear inside the one-person spacecraft. Cooper's flight was not an easy one. Near the end of his 22-orbit 34-hour mission, system after system in his capsule mysteriously started failing. He had to take over manual control and pilot the craft through a risky re-entry into the atmosphere.

What went wrong? An investigation showed that his urine bag leaked and droplets got into the electronics, hobbling his automatic systems, Roberts said.

Everybody poops

If rogue urine sounds problematic, think about the agony floating feces could inflict inside a cramped space capsule. When NASA started planning longer missions, they had to take astronauts' bowels into consideration.

The space agency's next project, Gemini, put two astronauts side-by-side in a spacecraft, testing out the crucial maneuvers that would bring the Apollo spaceflyers to the moon. To show that humans could survive in space for two weeks, Jim Lovell and Frank Borman spent 14 days flying in Gemini 7, the longest manned mission at the time.

"They had no toilet in there," Roberts said. "What they had was basically a plastic bag every time they had to do a No. 2."

Space toilets didn't become much more sophisticated by the time the first Apollo missions launched. Astronauts like Buzz Aldrin and Neil Armstrong had fecal collection bags that stuck to their bottoms with adhesive when they had to go. And microgravity could make things messy.

"There's a problem of separation," Roberts said. "Whatever comes out of you doesn't know it's supposed to come away from you." Each fecal collection bag came with a "finger cot" to allow the astronauts to manually move things along. Then they had to knead a germicide into their waste so that gas-expelling bacteria wouldn't flourish inside the sealed bag and cause it to explode. [Space Quiz! The Reality of Life in Orbit]

The entire ordeal often took 45 minutes to an hour to complete in the Apollo spacecraft, Roberts said. To minimize their bowel movements, astronauts had a high-protein, low-residue diet — think steak and eggs and other foods that are don't make a lot of waste after they are absorbed by the body.

Urinating wasn't much easier for the Apollo crews. Their urine collection device was basically a condom-like pouch attached to a hose that vented out into the vacuum of space at the turn of a valve. By the astronauts' own accounts, it was more than a little unsettling to use the device, Roberts said.

Astronaut potty training

Today, going to the bathroom in space is much less tedious, but it still requires careful attention — and even space toilet training. The reusable space planes of NASA's retired shuttle program had toilets using airflow to draw waste away from the body in place of Earth's gravity. The International Space Station has commodes with a similar design.

"For No. 2, it's kind of like a camp potty, where you use that to contain the solid waste and that gets burned up in the atmosphere eventually on a spacecraft," NASA astronaut Nicole Stott told elementary students today (Aug. 29) during a video chat from NASA's International Space Station Mission Control in Houston. "For No. 1, it's basically a hose, we call it a urine hose, that has a vacuum on it."

The "positional trainer" space toilet is for practice only, as it does not function. Hole diameter = 4 inches. (Image credit: NASA)

Astronauts go through "positional training" on Earth to make sure solid waste goes directly into the narrow opening of these space toilets, Roberts explained. The mock toilet has a camera at the bottom. Astronauts don't actually go to the bathroom during training, but by watching a video screen in front of them, they can check that their alignment is spot on.

"If you get stuff around these air vents that are providing the suction in there, things can get really clogged up and you can damage a multimillion-dollar toilet fairly easily," Roberts said.

Breaking a toilet is indeed expensive and inconvenient — not to mention unhealthy. After the sole toilet on the International Space Station had been plagued by a series of problems and breakdowns, NASA bought a second, $19 million Russian commode that was installed in the orbiting outpost's U.S. segment in 2008.

As for peeing, each astronaut is given his or her own funnel — made in different shapes for men and women — which attaches to a hose on the toilet. But as gravity diminishes in space, ego apparently doesn't.

"They had three different sizes of funnels and the guys were always choosing the largest size," Roberts said of the astronauts in the shuttle program.

Waste not, want not

In 1986, the Soviet Union built the Mir space station, which had a bathroom with a toilet that vented the waste out into space. By the time space officials were retiring Mir in 2001, the space station's solar panels had lost about 40 percent of their effectiveness, Roberts said.

"They realized that a large part of the damage to these solar panels was frozen urine floating in space at very high speeds," Roberts told his audience.

The Expedition 19 crew participates in a toast aboard the International Space Station. (Image credit: NASA TV)

Today on the International Space Station, a $100 billion orbiting outpost that has been staffed with rotating crews since 2000, urine gets recycled into drinking water through a filtration system.

Fecal matter, meanwhile, often gets packed up and cast off from the space station with other trash in capsules that burn up in the atmosphere, Roberts said. But with longer missions, like flights to Mars, some researchers are thinking about how to recycle feces, too. For example, some scientists propose that human waste could line the walls of future spacecraft to act like a radiation shield, protecting astronauts from the harmful effects of cosmic rays.

Follow Megan Gannon on Twitter and Google+. Follow us @Spacedotcom/, Facebook or Google+. Originally published on SPACE.com.