The label is scrawled and inky, but it unmistakably says "Nyassa. Dr Livingston." Despite the spelling mistake, it's the Doctor Livingstone, I presume (quite rightly). Suddenly we are transported back to tropical central Africa in the early 1860s. David Livingstone was in what is modern-day Malawi, where it is hot and dry or hot and humid, except in the freezing night-time highlands. Livingstone's wife Mary had recently died, and members of his expedition were starving by the end of a long trip.

For all this, the medical missionary was also a professional explorer, and what he had found was a new plant he called Faroa nyasica. The sample of dried flowers, stems, leaves and roots (like a shrivelled brown miniature hydrangea, though it is unrelated) was preserved and taken back to England, where it was donated to the Royal Botanic Gardens at Kew in west London, taped to the top corner of a piece of paper and filed. And there it still is, along with 7 million other specimens stored in Kew's Herbarium – the 18th century building attached to the grounds of the gardens dedicated to this purpose.

David Simpson, one of the assistant keepers of the Herbarium, shows me several specimens that illustrate its history, encompassing the rise and fall of the British Empire and figures including Captain Bligh, Charles Darwin and the Hookers of Kew (Sir William Hooker was the first director of the Royal Botanic Gardens, followed in that role by his son, Joseph, in 1865). There were many lesser-known adventurers, too, successes and failures who gave up their creature comforts – even their lives – to help build what is believed to be the world's finest collection of samples of plants and fungi and related diaries, journals, letters, books and paintings .

The Herbarium might be run by "keepers", but it is an active research centre: every year many of its 180 scientists travel the world, returning with 30,000 to 50,000 new samples. They are mapping new or lost discoveries (last year more than 250 of 2,000 newly "discovered" plants were found by Kew staff) and examining how ecosystems are coping in the face of human exploitation and climate change.

Each week, on average, 50 scientists visit the Herbarium to consult the specimens, and hundreds of samples are loaned out elsewhere. Every 40 years, on average, the building has to be extended to cope with the growing collection, with the opening of a new wing officially celebrated this month.. In two weeks' time, scientists at Kew will also announce the results of the most comprehensive study ever to find out how many of the world's one million or so named plants are at risk of extinction.

"This collection is not a museum," says David Simpson. "It's a museum in one sense, but it's also a well-used, vitally important collection that's equivalent to a database of plant information. Plants are not just beautiful and decorative; without them we simply couldn't survive. From the sheets we sleep on, the clothes we wear for warmth and the food and medicine we depend on, plants are invaluable to humanity; their diversity sustains us now, and in the future it will enable us to adapt, innovate and ultimately to survive."

History's first enthusiastic botanist, as Carolyn Fry recounts in her recent study of the subject, The Plant Hunters, was the bearded Queen Hatshepsut, an Egyptian pharaoh in the 15th century BC. Reliefs from her prosperous reign show ships loaded with ebony and myrrh trees, as well as apes and panther skins taken from a mysterious land called Punt (its identity is still disputed). Later, Alexander the Great sent home specimens from his wars in north Africa and the east, and successive armies transported plants into their new territories: the Romans sowing wheat, corn, barley and olives to feed their armies; Muslims spreading orchard fruits like sour oranges, lemons, limes and apricots, and showy flowers – most famously at the Alhambra palace in the Spanish city Granada.

In the 16th century, what would now be called botanical gardens began to be created. The garden established at Padua, Italy, in 1545, to grow flowers for medical use is now recognised as the world's oldest of its type still to be found in its original location. It was followed quickly by "physic" gardens in Florence, Bologna, Leiden, Paris and Oxford. The medical use of plants is still important to botanical gardens, but it was not long before they also became showcases for exotic species, fuelling a passion that introduced tulips, rose bushes and pear, quince and mulberry trees to Britain.

It was when this fashion for the exotic was joined by a new national mission – the Empire, again – that Kew Gardens emerged in the 1750s in the grounds of the royal home of Frederick, Prince of Wales and, after his death, his wife Augusta, who wanted it to "contain all the plants known on Earth". The Kew Herbarium, Library, Art and Archives, to give it its full name, was founded later, in 1852-53. By acquiring specimens from other herbaria, including the personal collection of the first director, William Hooker, its history now stretches back long before that. The oldest item in it is a 4,000-year-old olive tree branch from Tutankhamun's tomb, but this is considered too "scrappy" to qualify as the oldest official specimen. That honour goes to Indigofera astragalina, a member of the legume – or pea and bean – family collected by Daniel du Bois at Fort St George in India in 1700.

In some ways, little has changed about the way collectors work: most plants are still collected, dried between sheets of paper in presses, wrapped in newspaper and taken back to west London to be identified, labelled, stuck onto acid-free "Kew" archive paper (big folio sheets), and stored – much as they were 300 years ago, except everything is now also frozen to minus 35C for three days to kill off insect pests and their eggs.

Labels themselves reveal the history of how the collection – and the science of plants – has developed over the centuries, however. Plant taxonomy was given structure by the 18th century Swedish botanist Linnaeus: on the basis of their sexual organs (a system described by one critic as "loathsome harlotry"), every plant was assigned two Latin names – the first denoting its genus (or clan), the second denoting the species, often followed by the name or initial of the first person to "describe" it to science. Solanum caule inermi herbaceo, foliis pinnatis incisis, racemis simplicibus, for example, became Solanum lycopersicum – that is, a tomato. Later collectors provided more useful information: specimens from AFG Kerr, who spent much of the 1920s and 30s exploring in Thailand, are labelled with an exact date as well as details of their relevant location and further notes (although these labels are hand-written and hard to decipher).

Samples today come with with further detail, involving GPS data, and are computer-generated so they can be more easily read. There is also an ongoing project to "digitise" the collection online.

Conditions for collecting plants have improved, too. The Herbarium's collection of letters is a treasure trove for general historians, and a sometimes gruesome reminder of their trials. "People have an idea an English gentleman went out and said 'oh look, a plant', and somebody dug it up and took it home; whereas these guys were going through all sorts of strange trials and tribulations," says Chris Mills, assistant keeper of the library and archive.

Before he succeeded his father as Kew's director, the young Joseph Hooker wrote from the Himalayas in November 1849 that he and his companion had been "seized, guarded and interrogated with intimidation".Less ultimately successful was George Ramage who, after sending back a poor selection of plants from the West Indies in the late 1880s, wrote to justify his expenses to Kew's then director : he pleaded that he had had "neither alcohol nor tobacco... society or amusement," and luridly described suffering dysentery, malaria and an outbreak of ground itch which made his left ankle swell "to quite twice its size, and at one time a watery serum poured out of it so fast as to form a pool on the floor".

One of Kew's current botanists, Martin Cheek, works in west Africa, often following in the steps of another fabled collector, mid-19th century German botanist Gustav Mann. "Quite often people went out there for six weeks and died," Cheek says. "If you go to the graveyard in Douala [in Cameroon] you see all the graves."

Today's collectors use helicopters to reach remote locations and have the benefit of inoculations, repellents and quick-dry clothing. But they still face dysentery and diseases, mosquitos and tsetse flies – perhaps the most dreaded biting insect – while spending weeks living in tents with few comforts. "You come back and say 'I don't want to do that again', and then a few weeks later you do," says one of Cheek's colleagues, Marcella Corcoran.

Much of Kew's work is now dominated by partnership and conservation. The first specimen of the half-dozen or so collected of each plant is left in the country of origin, and the naming of new species and subsequent academic publications are shared with local scientists. Professor David Mabberley, current keeper of the Herbarium, Library, Art and Archives, says: "The purpose [of a herbarium] is as a record of plants, in particular places, at particular times." Using what is in effect an evolving map of the genetic distribution of plant material around the planet, scientists can work out how to restore "trashed" ecosystems and where to find new disease-resistant relatives of important crops should they be needed. But as well as these "selfish" human concerns, Mabberley says the scientists also feel a "rather more religious" motive. "Who are we to destroy everything in the world? Shouldn't we be trying to do something to conserve it?" he asks.

One further revolution is taking place in the Herbarium buildings by the Thames. As well as greatly expanding the library, and public access to it, and lifting much of the archive out of a damp basement, the new extension is making way for a radical rearrangement of the collection. First the two most insect-prone families – the economically important Fabales (including the legumes and milkworts) and the Compositae (the daisy or sunflower family) – will be moved into the new wing. This will then allow for the reorganisation of all 7 million specimens on the basis of their DNA – instead of the centuries-old method dependent upon physical appearances.

David Mabberley believes that eventually 10-12% of all the plants in the collection will be reassigned to different families. Already, among the more commonly known species, DNA testing has revealed that many of the Scrophulariaceae (or foxglove) family, though similar in appearance, are not related at all; one, the popular veronica, is to be moved in with the plantains (Plantaginaceae), while the buddleias will join their newly discovered foxglove kin.

For identification, however, the type specimens will continue to be the reference point, says Mabberley. "We have great forebears and we are all aware of that," he says. "One of the interesting things about our profession is we have to take notice of the historical aspect of the subject all the time because we use the earliest name available for labelling plants."

For botanists in the field, old-fashioned techniques still have their virtues. "When we're doing an identification," says Martin Cheek, "and using a specimen collected by Gustav Mann, we know they were all by themselves in a forest writing the label, then and there. And 150 years later all their efforts are being preserved and being used now."