PASADENA, Calif.— Scientists seeking to mine the huge trove of data gathered at great risk and expense in 30 years of space flight have found that much of it is so badly labeled or stored that extracting useful information can require years of ingenious detective work.

The results can be well worth the effort. For example, scientists working with 10-year-old data recently constructed the clearest picture yet of the biggest volcano on Mars. And scientists planning future lunar missions are sifting through data recorded in the mid-1960's to produce detailed pictures of the dark side of the Moon.

But it can take the frustrated researchers months and even years to pry useful information from the hundreds of thousands of magnetic tapes on which it is stored. Many of the tapes are uncatalogued. Some have been damaged by heat or floods.

Even tapes in good condition may be missing the documents needed to decode them. Others are so old that computer experts no longer understand how they were programmed. Still others can be processed only on machinery so outdated that little of the necessary hardware remains.

Even the tapes that were properly stored contain so much information that scientists are only beginning to catalogue it and put it on modern computer tapes and more advanced storage systems.

But even as they work their way through this enormous amount of material, much more lies ahead. The new ''Mission to Planet Earth'' program of the National Aeronautics and Space Administration is expected to generate more data in a day than has been generated by the entire previous history of the space program.

''These data are a national treasure,'' said Arthur I. Zygielbaum, manager of the Science Information Systems Office at NASA's Jet Propulsion Laboratory here. ''Our goal should be to save everything. Without tomorrow's context we don't know what is valuable today.'' The Jet Propulsion Laboratory, he said, is cataloguing its primary collection of about 200,000 space mission tapes, which are wound on 12-inch reels and stored in airtight metal cannisters. The tapes contain information on long-term trends like global climate change, tropical deforestation and the thinning of the atmospheric ozone layer, Mr. Zygielbaum said, as well as nuggets of information about the Moon and planets.

But the tapes' greatest value, researchers say, may lie in the light they can shed on scientific questions that have not yet been posed. For example, NASA scientists ignored ozone data gathered on space flights in the 1970's because the readings were so low they thought they were erroneous, Mr. Zygielbaum said. In the 1980's, after British scientists suggested that a dangerous thinning of the ozone layer was under way, NASA scientists were able to confirm the observation from the old data.

Similarly, in light of new theories about life originating in a medium of clay and water, a scientist recently went looking for evidence of clay on Mars and found it in old data.

Fifty years from now a scientist might come up with a theory about gravity waves and go looking for them in old Voyager data, said Edward Ng of the laboratory's information systems office. In science, he said, ''one man's noise is another man's signal.''

But sorting out what's on the tapes and putting it into usable form is a daunting enterprise. Two years ago, for example, Eric Eliason of the United States Geological Survey learned that more than 3,000 images from the Viking mission to Mars, obtained in the late 1970's, had never been processed from the master data record, the unprocessed data transmitted from the spacecraft.

Data Tapes as Puzzles

After tracking down the data, Mr. Eliason looked up the NASA documents that described how theywere entered. ''It was written in technical jargon,'' he said. ''Maybe it was clear to the person who wrote it but it was not clear to me 20 years later.''

There were copies of some old computer programs used to turn the raw data into pictures, he said, but the source codes the computer needed to run the programs could not be found and the computers themselves no longer existed.

Mr. Eliason then approached the data tapes as if they were encrypted puzzles. ''I tried to make sense of the raw data but in the first image I processed, all the pixels were backwards,'' said Mr. Eliason, referring to the tiny squares on a grid that make up a photographic image.

''I knew the images were in there somewhere,'' Mr. Eliason continued, ''so I talked to the old guys'' who designed the camera and other instruments. In this way Mr. Eliason learned that the Viking tape recorder ran forward and backward, so that data was encoded forward and backward as well. ''It took me months to learn all the intricacies of the data,'' he said.

After a year, Mr. Eliason succeded in writing a computer program that can extract the missing images of Mars. And last year, more than a decade after the Viking cameras collected data, he found the highest resolution image ever taken of Mons Olympus, the most signficant feature on Mars and the largest volcano in the solar system.