A fish tank brimming with urine is the first thing you see when you enter Jens Hauslage’s cramped office at the German space agency, DLR, near Cologne. It sits on a shelf by his desk, surrounded by the usual academic clutter of books, charts and scientific papers.

Rising from the centre of the tank are two transparent plastic cylindrical columns – around a metre in height. Spreading from the top of each tube is a bushy, healthy-looking tomato plant with green leaves, flowers and even a few bright red tomatoes.

“Are they edible?” I ask, half expecting to be told to stay well clear.

“Sure,” says Hauslage, a plant physiologist, casually twisting one of the tomatoes from its stem and handing over the euro-sized fruit.

I put it in my mouth. To be brutally honest, it’s not the nicest tomato I have ever tried: the skin is a little tough and the taste is slightly bitter. But it is, nevertheless, a healthy, edible tomato.

Recycled sweat

It’s hardly surprising the tomatoes in Hauslage’s office aren’t the tastiest. The plants have been specially bred to be grown in space. This experimental tank of urine, pipes and plants is the original prototype for a satellite designed to prove that tomatoes could be cultivated successfully on the Moon or Mars.

Right now, almost all the food on the International Space Station (ISS) is ferried up in cargo ships from Earth. The only exception is a few lettuce and cabbage leaves astronauts have managed to grow in a hydroponics solution. Most of the water on board the ISS, however, comes from astronaut urine. Liquid waste from washing, sweat and the toilet is almost totally recycled using a complex processing system. Today’s urine is tomorrow’s coffee.

But what if you could use the useful salts in astronaut urine to grow food? If humans are ever to live for long periods on the Moon or Mars, they will need a self-sustaining food supply. “You will need more than protein bars,” says Hauslage.

In Hauslage’s lab, there is plenty more urine swilling around – in vats, funnels and hoses  

“The Earth is a closed biological system with plants producing oxygen and food, then you have the animals and the microbes to produce all the degradation processes in the soil,” he says. “Without these systems, no sustainable long-term life-support system will be viable.”

In his lab, there is plenty more urine swilling around – in vats, funnels and hoses. Most of the urine is artificial – mixed so the scientists know the exact chemical composition for their experiments – but some comes from human volunteers. The walls are lined with grey plastic drain pipes, attached to plastic boxes full of bubbling artificial urine. At the centre of the room, larger terracotta-coloured pipes rise from plastic barrels of urine.

“The smaller columns can handle the urine of one person for a day,” explains Hauslage. “The big columns can handle the urine of four to six people.”

Each of these columns is packed with pumice stone – solidified lava that is riddled with holes – home to rich colonies of bacteria. These microbes feed on the urine pumped through the pipes, some bacteria convert ammonia into nitrites and others convert this into nitrate salts – fertiliser.

This is a controlled laboratory version of the nitrogen cycle that takes place naturally in soils and watercourses on Earth. As well as urine, this closed-loop biological system could be used to process leftover food or leaves that drop from a plant.

Considering we are in a room filled with gallons of urine, there is no smell  

Curiously, considering we are in a room filled with gallons of urine, there is no smell. “The degradation of urine into carbon dioxide and ammonia is really fast,” says Hauslage, “and the bacteria inside our filters are fast too.”

Having developed the technology in the lab, the DLR science team is now taking it into orbit. Later this year, the space agency will launch its Eu:cropis mission (the acronym stands, somewhat tortuously, for Euglena and Combined Regenerative Organic Food Production in Space), a metre-wide cylindrical satellite containing two miniature greenhouses.

Launched on a SpaceX Falcon 9 rocket, the satellite will orbit the Earth carrying tomato seeds, a tank of synthetic urine and bacterial colonies. The spacecraft will spin to simulate the gravity of the Moon for the first greenhouse. After six months the spin rate will be increased to simulate Martian gravity when the second greenhouse is brought online.

Initially oxygen will be produced by a colony of green algae – the Euglena of the acronym – although eventually the tomato plants will produce more oxygen than carbon dioxide.

“After launch we’ll spin the satellite and water the system,” says Hauslage. “The tomatoes will germinate and we’ll feed the system with urine to produce tomatoes.”

The plants will be carefully monitored with an array of 16 cameras, with data sent back to Earth four times a day. Although this isn’t the first time tomatoes have flown in space, it is the first satellite dedicated to growing plants in a closed system.

If the mission proves successful, then this could provide a way forward for growing plants on other worlds. But how about also using the other human waste product: faeces?

In The Martian, we see Matt Damon living off potatoes on Mars, cultivated in a soil of human excrement. Currently solid waste on the ISS is bagged up and packed into supply ships to be burnt-up in the Earth’s atmosphere.

“For me as a scientist, faeces is not quite gold like urine,” says Hauslage, “but it contains a lot of potassium which we need for a good fertiliser.” There are, however, dangerous pathogens in this solid waste that would need careful handling and processing.

Nevertheless, it is likely that nothing in a future colony on the Moon or Mars will be thrown away – everything will need to be recycled. And feeding dozens of colonists on a remote world is going to prove a challenge.

“You need a lot of calories, so you have to produce a lot of potatoes, cucumbers, tomatoes and so on and you need protein and fat,” says Hauslage. The latter food group is a particular challenge, but his team is already on the case: “We’ve also got an experiment producing fat with algae solution using our urine water.”

Yum. Just don’t expect food grown in space to win any Michelin Stars.

Join 800,000+ Future fans by liking us on Facebook, or follow us on Twitter.

If you liked this story, sign up for the weekly bbc.com features newsletter, called “If You Only Read 6 Things This Week”. A handpicked selection of stories from BBC Future, Earth, Culture, Capital, and Travel, delivered to your inbox every Friday.