Like most girls in her neighbourhood in Tehran, Tahmineh is a virgin. In her world, virginity is still revered. For many men, a woman’s virginity is a non-negotiable prerequisite for marriage. Even among some of the richer classes that ostensibly live more “western” lives, partying with alcohol and music, the men will happily sleep around but will want to marry someone “pure”. Virginity is seen as a marker of decency, of good family stock and morals.

In the narrow, twisting clutch of roads where Tahmineh lives, revealing your hair even to an uncle or a male cousin is not acceptable. Here, a woman’s virtue is the cornerstone of life, and local people blame bad hijab and declining morals for everything from high inflation to unemployment. Women live under constant risk of being branded loose for behaviour as anodyne as laughing too raucously or wearing the colour red.

Tahmineh wears the all-encompassing, black chador because her parents insist on it, and because neighbours in her conservative community gossip about women who choose to wear the headscarf and manteau, the overcoat that is meant to keep curves concealed. But in Tehran, being a virgin does not mean that Tahmineh has not had sex. “I first had anal sex when I was 21. Of course I want to have proper sex, but until I know for sure that my boyfriend wants to get married, I can’t risk it.”

Before Tahmineh graduated to anal sex, she and her friends were having la-paee (literally, “thigh”) sex, where the man uses a woman’s clenched thighs to orgasm. Tahmineh believes there are rising numbers of girls like her, who are from religious or traditional families but prepared to experiment sexually before marriage.

“Most girls in my area think that just being in a confined space with a boy is a sin, but my best friend has had la-paee sex, and I know lots of girls from less strict families who are allowed to hang out with boys, but who are still expected to be virgins, so they all have anal sex instead.” This phenomenon is so ubiquitous in Tehran that anal sex has become the butt – pun intended – of many a Tehrani joke.

For more than 30 years, the Islamic Republic has been obsessively battling against sex. It is preoccupied by how and with whom its people are having it. Lawmakers and scholars devote hours to discussing sex, condemning sex and sentencing people for having sex. Mullahs on television and radio philosophise and advise about it, sometimes in surprisingly lascivious detail. Government posters warn of the link between immodest dress and dubious morals; find-a-fatwa websites warn of the perils of self-love (everything from psychological damage to wreaking havoc on the nervous system) and offer cures to masturbators (lots of prayer and fasting).

As with anything that is suppressed or banned – such as alcohol, which flows through homes the length and breadth of the city – people have learned to sidestep the restrictions. And they are hungrier than ever for that which is not allowed. There is a sexual awakening in Tehran, and it is spreading beyond the rich, northern foothills of the city, where the more liberal and secular families live. There are some parallels with the sexual revolution that followed Franco’s fall in Spain, mainly that it is a backlash against repression, but in Tehran it is happening underground and behind closed doors. Graphic photos are bluetoothed and texted across the city; internet chat rooms and social sites are full of hook-ups. Not forgetting the city’s “special” women – the government’s euphemism for prostitutes.

Nobody knows how many work in the capital but, in a city of about 12 million, the official figure of 300,000 is thought to be a considerable underestimate. To the untrained eye, they are almost impossible to spot – sex workers look no different from other Tehranis standing on roadsides waiting to hail cabs and sauntering through shopping malls; girls in jeans and trainers; housewives in slacks holding fraying handbags; glamorous women with fake Chanel sunglasses perched on their heads. It does not help that the porn star look is so popular in Tehran, with blonde-highlighted girls, complete with collagen-engorged lips and shiny Botox foreheads, grinding their six-inch platform stiletto heels into tarmac all over the city. And if you know some of the darker secrets of this town – where to buy home-grown porn, who sells the purest drugs, the location of a big-bucks gambling den – you’ll also know that some girls operate on Facebook, displaying their goods in hold-ups, G-strings and baby-doll slips.

To find these girls, a user simply has to add the word jendeh – whore – after a name. Any name will do, for they are all there. A price list and services offered are found in the About Me section, with instructions on how to buy, which usually involve topping up pay-as-you-go phone credit before arranging a rendezvous. Sometimes punters are ripped off, or they are scared off by rumours of government-planted honey traps.

Tehran has many social layers that are mixed up with religion, money and class, and each group lives by its own set of rules. University is one of the few spheres where people from all backgrounds get the chance to socialise. Tahmineh credits her time at university as the experience that changed her perception of sex and morality. It was the first time she had been exposed to people with values different from her own.

“Before, I wasn’t allowed to mix with boys, not even members of my family. Then at university, I saw that some couples went out with each other and didn’t try to hide it. It was a revelation for me, as it wasn’t treated as something terrible. And I noticed that the women who were more independent and had boyfriends seemed happier. I also couldn’t deny my body’s natural needs,” Tahmineh says.

Some shifts in attitude in Tahmineh’s community have been more obvious. “My mum still whispers the word divorce, as it’s still seen as a shameful thing, but whereas ten years ago she didn’t know anyone who had divorced, now she knows two divorcees,” she says. Over the past ten years, divorces have tripled in Iran, with one in every five marriages ending – the ratio is even higher in the capital.

Since graduating in business studies, Tahmineh has not been able to find a job and she still lives at home with her parents. She is forced to lead a double life, sneaking out to meet boys in coffee shops far away from spying eyes. She blames a lack of independence for her need ultimately to play by the rules and keep her defiance a secret. Even if she were to earn enough to cover rent and food, her parents would never allow her to move out.

Like Tahmineh, Zahra is also from a conservative family in south Tehran and she, too, lives a double life. But unlike Tahmineh, she has broken free. She was 16 when she first fought back and refused to conform, insisting on wearing the hijab and manteau instead of the chador. That was the first of many battles she fought with her parents, who were fearful that she would be seen as sexually available, which would not only bring shame on the family, but result in Zahra being condemned to lifelong spinsterhood. Zahra realised that the only way she could escape was to earn her own money. Her parents were initially shocked, as single women living on their own are considered to have dubious morals. Even finding a flat was a struggle; many landlords refuse to rent to single women. In the first place she lived, the female residents of her block signed a petition to have her thrown out, afraid that she would entertain male company and desecrate the moral sanctity of the community.

“When I first moved out, where I’m from, a girl living on her own was unheard of, but now there are so many flat-shares of single girls that slowly the older generation are coming round to the idea,” she says. “That’s partly why my parents have found my situation a little easier to accept.” Her parents are now proud of her independence, not least because she is earning more than her father and is helping her family financially.

Zahra now moves in very different circles from the ones in which she was brought up, mostly because of her job in the media. Most of her social group are from traditional or lower-middle-class families, but independence has allowed them to forge their own paths and adopt more accepting codes of behaviour. Even though talking about virginity is no longer taboo among her peers, girls are still careful about who they share information with. Zahra lost her virginity a few years ago and has had two serious relationships.

“It’s still hard to trust a guy,” she says, “because sometimes they’ll act like they’re cool with you not being a virgin, and then after you sleep with them, they just dump you. It can work the other way, too, that if they think you’re a virgin, they just want the thrill of being your first, so they’ll feed you all this shit about wanting to marry you. It’s hard to be considered an equal in sex with guys here.”

For those worried about marriage prospects, there are solutions. A friend of Zahra’s recently had her hymen sewn up with a needle and surgical thread before her wedding night by a moonlighting GP who restores modesty and marriageability. The stitching service does not come cheap, and so, for those who cannot afford it, a trip to the bazaar can yield a virginity kit, which consists of a capsule filled with red liquid that is inserted into the vagina on the wedding night, ready to burst under pressure.

Liberal middle- and upper-class Tehranis enjoy more sexual freedom, and short-term relationships and one-night stands have become a part of life. In skinny jeans, John Lennon glasses and a retro-quiff, Kamran is a Tehrani hipster. Like most of his generation, he cannot afford his own home and he lives in an apartment in an average neighbourhood in north-east Tehran with his single mother. Tall, good-looking and sharp-witted, he is a hit with girls on the party scene, but despite a thriving sex life Kamran declares that romance in Tehran is dead. He laments that the repressive atmosphere has distorted sexual relations.

“Sometimes I just want to date a girl, get to know her and build up to sex. But here, it’s just – bang, you jump into bed at the first opportunity. The first thing you think about when you’re alone is: we better fuck, because you don’t know when you may get the chance again. Sex has lost its value.”

The government’s attempts at controlling the sex lives of its citizens have also politicised carnal relations. In a country where self-expression is fiercely discouraged, sex has become a form of dissent. Only in sex do many of the younger generation feel truly free. They have ultimate control over their bodies, if nothing else in their lives, and they have made them weapons of revolt.

“You could see it during the protests [mass street demonstrations after the contested election results in 2009]. It was like we took solace in having sex, and it was just another way of saying: ‘You can’t tell us how to live our lives,’ ” says Kamran.

Zahra thinks this is especially true for those from religious and conservative families like her own – in which governmental pressure has simply intensified social strictures – who dare to step outside the boundaries. Asserting her sexuality has also become a political act of equality.

“Nobody can tell me what I can do with my own body – nobody can tell me how to love. And when you meet a guy who really doesn’t care if you’re not a virgin, you know that he’s also saying, ‘I don’t believe in these rules,’ and that’s very powerful.”

The shifting attitude towards sex can be seen in the rise of sigheh – temporary marriage – in some more traditional parts of the city. Sigheh is approved by both God and the state, and is an agreement between a man (who can already be married) and a woman (who cannot) to form a union for as short as a few minutes or as long as 99 years. It is Shia pragmatism at its best, ensuring that even a quickie can be given an Islamic seal of approval and sanctified in the eyes of the Lord. Even though the practice is frowned on, it offers official respectability.

In a suburb of eastern Tehran, a mullah does swift business issuing temporary marriage certificates to young unmarried couples wanting to go on holiday together (a marriage certificate is needed in order to share a hotel room) and couples wanting to live together but not commit to marriage. The mullah admits that many of his clients are married men who keep concubines and use sigheh as protection from the law. Their wives rarely know about the husbands’ temporary marriages.

“At least they’re not being unfaithful!” he says, without irony. He bemoans the scourge of infidelity that is sweeping the city. The mullah does have a point; if nothing else, he has picked up on the mood in the city. Tehranis are natural-born complainers, and now, to the traffic, pollution, corruption, parking spaces, politics and the duplicitous dealings of the British, they have added a new complaint – infidelity. In richer suburbs in the north of the city, talk of extramarital affairs is surprisingly open. Everyone has a theory as to why Tehranis are so unfaithful, the most popular being a dearth of solvent men that has led to ferocious competition. Others say that it is simply because couples get married too young and have nothing better to do. Or that it is part of a sexual revolution.

For many, continually having to lie and hide natural urges is taking its toll on normal sexual interaction. Some of the younger generation are taking increasing risks and are having sex in parks and in cars, and flashing each other in public. They are filming themselves doing it, sometimes uploading the videos to the internet without even bothering to conceal their faces. Porn has spread through all age groups and social classes. It is bought and sold on the streets and in bazaars and swapped between friends. In some homes, triple-X porn is beamed in by satellite, the channels unlocked for a price by underground television technicians.

The government has even discussed in parliament how to dampen its citizens’ lust for porn. It has introduced a bill updating the law and enforcing stricter punishments for crimes including being found a corrupter of the earth, making it a capital offence. In the past few years, the courts have sentenced two people to death for running porn sites; one of them, an Iranian-born Canadian computer programmer called Saeed Malekpour, had his death sentence reduced to life imprisonment for “designing and moderating adult-content websites”, which goes hand in hand with insulting the sanctity of Islam.

The cyber police unit, launched in 2011 to fight internet crime and protect “national and religious identity”, announced a crackdown on internet and Facebook pages that promote pornography and prostitution, after which the numbers of prostitutes working through Facebook decreased dramatically. But trying to curb people’s most basic desire is an endless cat-and-mouse game. As quickly as websites are shut down, new ones appear, along with new proxy servers known as VPNs – virtual private networks – that circumvent the government’s internet filter by allowing computers to function as if they were in another country.

One group that has been particularly adept at coping under Islamic rule has been the gay community. Social media has invigorated the scene, with sites and apps such as Manjam and Grindr transforming the way men meet. “It’s made it much easier, and there’s a real little community now, thanks to social media,” says Reza, a handsome, well-educated trust-fund kid who works as an artist.

Reza thinks the increasing sexual libera­tion of Tehranis is also having a trickle-down effect on the gay scene. “You still have to be careful, of course, and you can’t come out to everyone, but at least in north Tehran we’ve got our own little bubble of freedom. It’s really hard for guys in the south of the city.”

Reza and his friends joke that they love cruising in south Tehran because it is so easy to pull. “They’re just gagging for sex, and I’m sure half the guys aren’t even really gay. But where they live, they just don’t have many alternatives.”

A batch of notorious cruising and cottaging hot spots is still going strong despite the punishments. The law on same-sex sodomy was recently amended, reflecting the state’s twisted attitude towards homosexuality: if the sex is consensual and the man playing the active role is not married and a Muslim, he will be flogged 100 times, whereas the man who plays the passive role will be put to death (unless he is a kafir, or infidel, having sex with a Muslim, in which case they will both be killed). In the Islamic Republic, it is better to bugger than to be buggered.

Back in the 1970s, Tehran was a cultural vanguard with a liberal and enlightened arts scene; it was as much a city of mosques as it was one of cabarets and whisky bars. Miniskirted women trod the same pavements as those in chadors, and people from across the social spectrum supported the revolution. Only months after it happened, Ayatollah Khomeini decreed the mandatory wearing of the hijab; there was an immediate backlash and thousands of women poured out on to the streets to protest. But fighting for social freedoms was deemed unimportant in the face of the bloodbath that followed the fall of the shah. Then the Iran-Iraq war began, and as it raged the voices of women were eclipsed by violence and the need to survive.

Since then, Iran’s population has exploded and technology has further eroded the regime’s ability to police its young; governance now treads the fine line between tightening the reins and tipping the country into revolt. As you might expect, changes in sexual attitudes have been far slower in conservative circles. The social stigma on being sexually active before marriage is unlikely to lessen until the government adopts a more liberal stance. Until then, Tahmineh and her peers will continue to find ways around the laws and societal rules; because not even the threat of death can stop people from having sex.

Ramita Navai is the author of “City of Lies: Love, Sex, Death and the Search for Truth in Tehran” (Weidenfeld & Nicolson, £18.99)