‘Berlin is a bugger’s daydream,” the 21-year-old WH Auden wrote to Christopher Isherwood, with news of the city’s 170 police‑controlled male brothels. By 1929, when his school friend joined him there, the metropolis was the world capital of sexual liberation with a decade-long reputation as “Babylon on the Spree”. In his 1939 novel, Goodbye to Berlin, Isherwood brilliantly captured the Weimar Republic’s decadent atmosphere of sexual experimentation, which was heightened by a sense of looming crisis. The city had been hit particularly hard by the worldwide recession; there was mass unemployment, malnutrition, economic panic and simmering political violence. “One suddenly realised the whole foundations of life were shaking,” Auden concluded.

In Berlin, Isherwood lived in an apartment owned by Magnus Hirschfeld’s Institute for Sexual Science, which occupied the grand mansion of the former French ambassador. The institute was decorated more like a wealthy private residence than a scientific establishment, with Persian carpets, a grand piano and glass cabinets full of porcelain. Free sex advice was dispensed in lectures and private consulting rooms and there were medical clinics for the treatment of venereal diseases and other sexual problems, as well as a library containing the largest collection of literature on sex in the world. There was also a research laboratory where the portly, walrus-moustached Hirschfeld – known as the “Einstein of Sex” – formulated dubious aphrodisiacs and anti-impotence medicines, and supervised the world’s first sex reassignment surgery.

Alfred Kinsey interview. Photograph by William Dellenback. Wellcome Images

The Institute also boasted a museum of sexual pathology that held up a mirror to the risque desires of Berlin’s inhabitants and became something of an unlikely tourist attraction. It was stuffed, Isherwood noted when he visited, with sado-masochistic and fetishistic props. He and Auden giggled as they went around displays of whips and chains, high-heeled boots, half-trousers sported by flashers under their coats, mechanical masturbation devices and transvestite accessories, including oversized lacy underwear worn by a Prussian officer beneath his uniform. Isherwood later admitted to having felt “a kinship with these freakish fellow tribesmen and their freakish customs”. He described the institute admiringly as a “sanctuary ... where sex was being treated with seriousness”.

The Institute of Sexology, a new exhibition at the Wellcome Collection, celebrates the scientific study of sex that Hirschfeld, along with Richard von Krafft-Ebing and Havelock Ellis, helped to found. Last week, I found myself in the Wellcome’s storerooms, wearing purple plastic gloves as I previewed some of the artefacts that will be on display alongside the scientific charts and graphs that gave early sexology a legitimate, disinterested air. It was like Christmas: everything was parcelled in bubble wrap, which curator Kate Forde carefully peeled open to reveal the erotica inside. Most of these objects were collected by Henry Wellcome, who was interested in amassing evidence of “phallic worship” as the origin of religiosity: there was a porcelain persimmon, in which were secreted a copulating couple, a phallic amulet with copper wings (one broken), and a saw-toothed anti-masturbation device intended for a young man. The handling of an ancient box, full of intricately carved tortoiseshell sex aids (Hirschfeld apparently had an identical set in his collection), made me grateful to be wearing archival gloves.

There was also a turn-of-the-century vibrator, with the unfortunate name Veedee; a pun on the Latin phrase, “Veni, vidi, vici”. The packaging made ambitious claims for it as a panacea, able to cure everything from colds to neurosis with its “curative vibration”. The device resembles a bulky hairdryer and was once a serious medical tool, used by doctors to induce the orgasms thought to reposition the wandering womb believed to cause hysteria. Before he began using hypnosis, Sigmund Freud, who claimed a certain expertise when he distinguished the vaginal from the clitoral orgasm (he considered the later immature and inferior, to the annoyance of 1960s feminists), employed electrotherapy and massage at his own clinic – one historian wonders if he might have once also operated as a “gynaecological masseur”.

L0076451 Carton of Ladywet condoms, Japan, 1970-Photo: Wellcome Library, London. Photograph: Wellcome Images/Wellcome Trust

The Wellcome exhibition makes clear that the pioneers of sexology, who followed Freud in putting sex at the centre of psychological life, were also political activists. Hirschfeld, who was homosexual, campaigned vigorously to have laws against both sodomy and abortion revoked, and argued for all consensual sex among adults to be considered outside the purview of the legal system. Communist psychoanalysts such as Wilhelm Reich, who moved to Berlin to join forces with Hirschfeld, believed that sexual liberation was the key to social revolution. Influenced by the Polish anthropologist Bronisław Malinowski, author of The Sexual Lives of the Savages (1929), Reich believed that the bonds of the family and marriage were bourgeois shackles, and that, following the example of the Trobriand Islanders of Papua New Guinea, children should be raised collectively and adolescents encouraged to pursue free sex. For Reich, the Trobrianders’ relaxed attitude to sexuality, and correspondingly peaceful culture, showed the possibility of primitive communism, of utopia on Earth.

However, the sexual revolution Hirschfeld and Reich envisaged remained elusive. As Jews, sexologists and communists, they were everything Hitler abhorred. Hirschfeld suffered a fractured skull when he was accosted in the street and beaten up by Nazis. In 1933, after Hitler assumed power, the Institute of Sex Research was vandalised by storm troopers – they poured ink over the photos, documents and archive files, smashed the exhibition cases, and played football with the erotic artefacts inside. A plaster bust of Hirschfeld, then in exile in Paris, was paraded on a wooden stake to the Opernplatz, where Brown Shirts tossed it on an enormous pyre of 100,000 “un-Germanic” books. Hirschfeld was sitting in a cinema when he happened to see newsreel footage of the fire, which he described as like witnessing his own funeral. Reich’s works – including The Function of the Orgasm (1927) – were among those burned and, similarly blacklisted, he was also forced to flee Berlin.

Collection of sexual aids, with instructions. Photograph: Wellcome Images

In 1939 Reich emigrated to the US, where he joined Malinowski at the New School of Social Research, then known as the University of Exile. There he built an Orgone Energy Accumulator, a box that he thought could channel the libidinous force of the universe. Gullible Beats and bohemians – including Burroughs, Ginsberg, Bellow and Mailer – sat inside patiently hoping for sexual enlightenment (visitors to the exhibition can try an orgasmatron for themselves). By the time Reich arrived in the States, Alfred Kinsey, a 44-year-old professor of zoology at Indiana University had just begun collecting interviews for his monumental study of American sexuality. Kinsey taught what was quaintly known as the “marriage course” at the university (nicknamed the “copulating class”). “In an uninhibited society” – Kinsey began the class with a reference to the Trobriand Islands – “a 12-year-old would know most of the biology which I will have to give you in formal lessons”. Disappointed by the dearth of scientific literature on sex – “mainly morals masquerading under the name of science” – he began interviewing people about their sexual histories in an ambitious attempt to fill the void.

Kinsey quite deliberately made no moral evaluations of his subjects and guaranteed them complete confidentiality: he avoided euphemism, and rattled off between 350 and 521 direct questions, maintaining eye contact all the while. Each interview took an average of one to three hours per case, depending on the subject’s experience (the longest took 17 hours). By using a unique secret code, he estimated he could boil his research down from what would have taken 20 to 25 pages to a one-page grid, information that was punched into Hollerith cards and tabulated using an IBM computer. Kinsey’s carefully coded files – which formed the basis of his landmark studies, Sexual Behavior in the Human Male (1948), and Sexual Behavior in the Human Female (1953) – were kept in a series of locked fireproof filing cabinets at The Institute for Sex Research. Kinsey boasted that the 18,000 case histories he collected – from paedophiles to politicians (sometimes both) – contained enough material “to blow up America”.

Kinsey’s Institute, which oversaw a renaissance in sex research, was modelled on Hirschfeld’s pioneering clinic in Berlin. An obsessive collector, Kinsey amassed a similarly diverse museum of sexual ephemera, some of which will be on display at the Wellcome. Though he publicly dismissed Hirschfeld, who had conducted his own sexual survey, as more of a special pleader than objective scientist, Kinsey was himself a lot more prescriptive than he liked to admit. Underneath his cool scientific detachment was a crusading humanitarianism that bubbled up between the lines of everything he wrote. Clara Kinsey claimed that her husband’s work represented “an unvoiced plea for [sexual] tolerance”. Building on Hirschfeld’s doctrine of “sexual indeterminancy”, Kinsey developed a sliding scale that was radical in that it made sexual orientation a matter of degree: while only 4% of men were exclusively homosexual, 37% had enjoyed a homosexual experience (“more than one male in three,” he emphasised).

Woman riding man, coloured postcard (1840-1902). Photograph: Wellcome Images/Wellcome Trust

Kinsey used his statistics to ridicule the existing sex laws (sodomy, for example, was illegal in Indiana, as was oral sex): 90% of the nation’s men and 80% of its women, he was fond of saying, could theoretically be sent to prison for what they’d done sexually. Conservatives attacked him for undermining the institution of the family; McCarthyites accused him of spearheading a communist plot to weaken American morality; and J Edgar Hoover launched an investigation into Kinsey’s background in an attempt to undermine him. Nevertheless, in 1955, a year before Kinsey’s death, the American Law Institute drafted an influential Model Penal Code. This drew on Kinsey’s studies to reject the concept of “deviant sexual behaviour” and led to the reform of the sex laws.

Kinsey’s statistics helped to lay the foundations for the sexual revolution of the 1960s, when views of sexuality were transformed in ways he could not have imagined. William Masters and Virginia Johnson continued Kinsey’s work, focusing not only on personal histories, but the biology of sex. (Few knew that Kinsey had conducted similar research, filming his team of sex researchers having sex with various volunteers.) In their secret laboratory at Washington University, Masters and Johnson used specialist equipment, including a camera hidden in a transparent dildo, nicknamed Ulysses, to record the physiology of coitus. The Wellcome juxtaposes the resulting electrocardiograms, included in their book Human Sexual Response (1966), with original drawings from Alex Comfort’s bestseller, The Joy of Sex (1972). One of these features a Neanderthal-looking man lost in the equally bushy armpits of his female lover.

Following the birth of the contraceptive pill, which was licensed in 1960, feminists seized on the similarities Masters and Johnson detected between male and female sexual responses to insist on women’s right to orgasmic pleasure. The duo, who married in 1971, pioneered “sensate therapy” to treat sexual dysfunction, and controversially used sexual surrogates to that end. However, unlike Hirschfeld and Kinsey, they didn’t exhibit an unreservedly open response to sexual difference, claiming in a 1978 book to have “cured” several homosexuals. In the 1980s they also fuelled hysteria about Aids, claiming it to be a disease of biblical proportions that might be transmitted by mosquitoes and toilet seats. The Wellcome show ends with this era, which Hugh Hefner termed “the great repression” because the climate of fear it engendered put an end to the optimistic rhetoric of liberation that had recently surrounded sex.

A man ejaculating while holding a net for birds. Photograph: Wellcome Images

One exhibit on display is a leaflet, posted through UK doors in 1989, titled “Aids: Don’t Die of Ignorance”. The crisis was the catalyst for the National Survey of Sexual Attitudes and Lifestyles, carried out in 1990 and the most ambitious sexual study since Kinsey (Further NATSAL surveys were collected in 2000 and 2013.) Margaret Thatcher, then prime minister, objected to the project, deeming the intimate questions an invasion of people’s privacy, and controversially vetoed government support. The Wellcome stepped in with the necessary money, and almost 19,000 people were interviewed (more than Kinsey managed in his lifetime), data that helped researchers predict the spread and transmission of the Aids epidemic.

If the Wellcome Trust comes across in the trajectory of the exhibition as heroic, it should be remembered that the money they invested in this research was minuscule compared to the huge amounts of money that Wellcome plc, part-owned by the Trust at the time, had made from AZT, an antiretroviral drug used to control HIV infection (a crucial ingredient of which is herring sperm). AZT had been on sale in the United States since 1987, and was one of the highest priced drugs ever marketed, making it prohibitively expensive to anyone without health insurance who had the disease. In January 1990 Act Up, the AIDS Coalition to Unleash Power, picketed the Wellcome plc shareholders’ meeting, accusing it of profiteering, and the organisation was in desperate need of some good PR.

• Christopher Turner’s Adventures in the Orgasmatron: The Invention of Sex is out in paperback from Fourth Estate. The Institute of Sexology starts at the Wellcome Collection, 183 Euston Road, London NW1, on 20 November. wellcomecollection.org.