I think a fair amount about the fact that we're all going to die. It occurs to me at incredibly inopportune moments – I'll be standing in a bar, having managed to get an attractive guy to laugh, and I'll be laughing, too, and maybe dancing a little bit, and then everything goes slo-mo for a second and I'll think: are these people aware that we're all going to the same place in the end? I can slip back into conversation and tell myself that the flash of mortality awareness has enriched my experience, reminded me to just go for it in the giggling and hair-flipping and speaking-my-mind departments because… why the hell not? But occasionally the feeling stays with me, and it reminds me of being a child – feeling full of fear but lacking the language to calm yourself down. I guess, when it comes to death, none of us really has the words.

I wish I could be one of those young people who seems totally unaware of the fact that her gleaming nubile body is, in fact, fallible. (Maybe you have to have a gleaming nubile body to feel that way.) Beautiful self-delusion: isn't that what being young is all about? You think you're immortal until one day when you're around 60, it hits you: you see an Ingmar Bergman-y spectre of death and you do some soul-searching and possibly adopt a kid in need. You resolve to live the rest of your life in a way you can be proud of.

But I am not one of those young people. I've been obsessed with death since I was born.

As a little kid, an unnamed fear would often overtake me. It wasn't a fear of anything tangible – tigers, burglars, homelessness – and it couldn't be solved by usual means like hugging my mother or turning on Nickelodeon shows. The feeling was cold and resided just below my stomach. It made everything around me seem unreal and unsafe. I could most closely equate it with the sensation I felt when, aged three, I was taken to hospital in the night with sudden hives. My parents were away, on a trip, so my Brazilian babysitter Flavia had rushed me to the ER, where a doctor placed me on a high bed and pressed a cold stethoscope between my shoulder blades. On our way into the hospital, I was sure I had seen a man sleeping inside a mailbag. In hindsight, he must have been on a gurney, covered in a dark blanket. Maybe he was comatose or even dead. The doctor removed my shirt, checked under my armpits, and all the while I hovered above us, dissociated, observing.

This chain reaction of observations and implications would repeat itself throughout my childhood, in the face of this unnamed fear, and I came to refer to it as "hospital feeling". I decided it could be cured by taking a swig of grape juice.

I was able to put a finer point on this feeling when my grandmother died. I was 14. I had recently coloured my hair and bought a satin tube top, a transition I considered to be evidence of irreversible maturity. I showed up to my last visit with my grandmother in rich brown lipstick and a slim collarless coat, bought on sale at Banana Republic. I painted my dying grandmother's fingernails carefully with a pearlescent polish by Wet n Wild and promised to return for lunch the next day. But there was no next day: she died late that night, my father by her side. The following morning, when he recounted her passing to us, was the first and last time I saw him cry.

Until I was about 12, my grandmother was my best friend. Carol Marguerite Reynolds – Gram, as I called her – was in possession of a swirling bob of snow-white hair and only one eyebrow, a result of a lack of UV awareness. She was in the habit of drawing on the missing one with a grey-blue Maybelline pencil that didn't even begin to suggest natural hair growth. She wore pants from the maternity store to accommodate her distended belly and the kind of practical shoes that have, in recent years, become fashionable in Brooklyn. Her house smelled of mothballs, baby powder and a loamy moistness that emanated from her overstuffed basement. I called her every day at 4pm.

On the surface, she was traditional. Provincial even. A retired real estate agent in Old Lyme, Connecticut, with a passion for Dan Rather and a freezer full of cheap London broil, she wasn't particularly interested in our life in the city. (In fact, I remember her visiting only once, an event I was so excited about that I put out the milk for tea at 10am, and it spoiled by her 4pm arrival.) But the trappings of her domestic life hid what I now see was the soul of a radical. After attending a one-room schoolhouse in a town full of swamp Yankees – her family had been the first of their neighbours to have a car, which they drove across the frozen lake in winter – she had fled her sheltered life for Mount Holyoke College, Yale nursing school and then the army, where she was stationed in Germany and Japan, suturing wounds and removing shrapnel from German soldiers despite strict orders to let them die. She dated doctors (some of them Jews!) and adopted a dachshund named Meatloaf she'd found rummaging through the trash behind her tent.

Gram recounted her adventures with Plymouth Rock stoicism, but it was clear to me, even as a nine-year-old, that she'd seen far more than she was willing to discuss.

'I painted my dying grandmother’s fingernails carefully with a pearlescent polish by Wet n Wild and promised to return for lunch the next day. But there was no next day: she died late that night.' Photograph: Chris Buck for the Guardian

Gram didn't marry until she was 34 which, in 1947, was the equivalent of being Liza Minnelli on her fifth gay husband. My grandfather was massively obese and came from great wealth, which he had squandered on a series of misguided investments including a chicken farm and a business that sold "all-in-one sporting cages". But Gram saw something in him, and within two weeks they were engaged. From this union came my father and his brother, Edward, aka Jack.

The day after Gram died, my father and I drove up to her house one last time, and I listened to Aimee Mann on a Discman and watched the industrial landscape pass by. This drive had been a fixture of my childhood: abandoned hospitals and train tracks, signs for towns that didn't live up to their names, a stop in New Haven for pizza and gas. This, I remember thinking, is the end. Nothing had ever ended before.

As my father and Uncle Jack organised Gram's things in preparation to sell her house, I wandered the halls in her bathrobe, her crumpled tissues still in the pockets, wailing. They kept working, seemingly immune to the magnitude of the occasion.

"I can't believe she saved all these fucking receipts," my father hissed. "There's canned soup in the cellar from 1965."

"She was just here!" I shouted at the unfeeling adults. "And now she's gone! Her things are still in the refrigerator!"

When I emerged from the bathroom smelling her comb, my uncle took my father aside and asked him to please make me stop.

Enraged by the request, I retreated to her closet and switched to sniffing her pyjamas. My head throbbed with questions. Where is Gram? Is she conscious? Is she lonely? And what does this all mean for me?

The rest of the summer was characterised by a kind of hot terror, a lurking dread that cast a pallor over everything I did. Every ice pop I ate, every movie I watched, every poem I wrote was tinged with a sense of impending loss. Not of another loved one but of my own life. It could be tomorrow. It could be 80 years from tomorrow. But it was coming for us all, and I was no exception.

So what were we playing at?

Finally, one day, I couldn't stand it any more: I walked into the kitchen, laid my head on the table, and asked my father, "How are we supposed to live every day if we know we're going to die?" He looked at me, clearly pained by the dawning of my genetically predestined morbidity. He had been the same way as a kid. A day never went by when he didn't think about his eventual demise. He sighed, leaned back in his chair, unable to conjure a comforting answer. "You just do."

My father can get pretty existential. "You're born alone and you die alone" is a favourite of his that I particularly hate. Ditto "Perhaps reality is just a chip implanted in all our brains." He has a history of staring out into nature and asking, "How do we know this is actually here?" I guess I inherited it. I thought about Gram, about how long and complicated her life had been, and how it had now been reduced to a dumpster full of old canned goods and a vintage Pucci sweater I had already spilled tomato sauce on. I thought about all the things I hoped to get done in my life and realised: I'd better get cracking. I can never spend a whole afternoon watching a Singled Out marathon again if this is what's going to happen.

The fact is I had been circling the topic of death, subconsciously, for some time. Growing up in Soho in the late 1980s and early 1990s, I was aware of Aids and the toll it was taking on the creative community. Illness, loss, who would handle the art and the real estate and the medical bills – these topics hovered over every dinner party. As many of my parents' friends became sick, I learned to recognise the look of someone suffering – sunken cheeks, odd facial spotting, a sweater that no longer fit. And I knew what it meant: that person would soon become a memorial, the name on a prize given to visiting students, a distant memory.

Dunham with her father, Carroll. Photograph: Jason LaVeris/Getty

My mum's best friend Jimmy was a swarthy gay fetish photographer who was dying by the time I was born. One of my earliest memories is of a pale, feeble man reclining on the couch by the front windows of our loft, joking weakly with my mother about gossip, and family, and fashion. He was charismatic, talented, darkly funny. My mother helped him get his affairs in order, reached out to friends who hadn't seen him in a long time to say goodbye, navigated New York with his mother when she came to be with Jimmy in his final days. I still have a lot of guilt for screaming at Jimmy when he ate a banana I had been "saving", especially since he died a few weeks later.

The summer after sophomore year of college, I became convinced I, too, would die of Aids. I had ill-advised intercourse with a petite poet-mathematician who, afterwards, removed the condom, placed it under his pillow, and wiped his penis clean on his own curtains.

"Can I tell you a secret?" he asked as he returned to bed.

"Lay it on me!" I said.

"Well," he said, "last week I was walking around late at night and I accidentally wandered into a gay bar and I met this Filipino guy and let him come to my house, and he fucked me in the ass and the condom broke and then he stole my wallet."

I paused. "I'm so sorry that happened to you," I said.

It was about 100 degrees out, the kind of New York heat that chafes your thighs and makes the murder rate spike. I spent the rest of the summer in a hell of my own creation, imagining the virus taking hold, the things I'd never do, the children I'd never have, the tears my mother would shed as she lost yet another loved one to this pandemic. I'd done enough research to know that, were I infected, it wouldn't show up on a test for several months, so I simply waited and asked myself questions: was I strong enough to be an activist? What would it feel like to be the face of Aids in the industrialised world? Or would I simply hide until I died? I asked to have my wisdom teeth removed, just so I could be unconscious for a few hours. I tried to enjoy every bite of Tasti D and every laugh shared with my sister, knowing things would soon change. I made out with a computer programmer and wondered if I'd exposed him to the illness. By the end of summer I was officially "living with Aids".

Spoiler alert: I was fine.

As much as I wanted to believe the universe punishes you for fucking a minuscule bisexual, I had not contracted the virus. But the chilling spectre of my own death had been so all-consuming, I'd required dental surgery.

"I don't mind the idea of dying," my friend Elizabeth says, "but I'm stressed out about the logistics of the whole thing." If we are reincarnated, as my mother promises, how long do we have to wait around before we get inside that new baby? Is it a long line, like the Japanese girls lined up outside a newly opened Topshop? What if that new baby has mean parents? If we follow the Buddhist logic that we are becoming part of the glory of the universe, one huge consciousness, well, that's just too much togetherness for my taste. I couldn't even do a group art project in second grade. How am I going to share an understanding with the rest of creation? If this proves to be the case, I'm too much of a loner for death, but I'm also scared of being lonely. Where does that leave me?

After reading an early version of this essay, my friend Matt asked me: "Why are you in such a rush to die?" I was shocked by the question, even a little pissed. This wasn't about me! This was about the universal plight, which I happen to have an exceptionally clear perspective on because of my inability to ignore it like some other nincompoops!

I had never thought of it that way, but Matt was right. The hypochondria. The intensity of my reactions to death, and my inability to disengage with the topic once it is raised. My need to make it clear to everyone that it's coming for them, too. My need to meditate on it. Is what's manifesting as a fear actually some instinct to resist being young? Youth, with its accompanying risks, humiliations and uncertainties, the pressure to do it all before it's too late. Is the sense of imminent death bound up in the desire to leave some kind of a legacy? I did once write, though never shot, a short film in which I held a massive funeral, heard everyone I love speak on the topic of me, then jumped out of my casket at the end and yelled, "Surprise!"

'I want to be enlightened, but it also sounds boring. So much of what I love – gossip and food and the internet – is here, on Earth.' Photograph: Chris Buck for the Guardian

I am still in my 20s, so a fear of death is, while reasonable in a macro way, also fairly irrational. Most people live through their 20s. And their 30s. And their 40s. Many people live longer than is amusing, even to them. So every time I think about death, when I lie in bed and imagine disintegrating, my skin going leathery and my hair petrifying and a tree growing out of my stomach, it's a way to avoid what's right in front of me. It's a way to not be here, in the uncertainty of right now.

If I live long enough and am given a chance to read this when I'm old, I'll probably be appalled at my own audacity to think that I have any sense of what death means, what it brings to light, what it feels like to live with the knowledge that it is coming. How could someone whose biggest health scare was a coffee-induced colon infection know what the end of life looks like? How could someone who has never lost a parent, a lover or a best friend have the faintest clue about what any of this means?

My dad, who looks pretty great for 64, is fond of saying, "You just can't fucking imagine, Lena." He can see the big event in the distance (his belief in robotics notwithstanding) and says things like, "Bring it on. At this point, I'm fucking curious." I get it: I know nothing. But I also hope that future me will be proud of present me for trying to wrap my head around the big ideas and also for trying to make you feel like we're all in this together.

Gram's sister is still alive.*

Doad is 100, with the energy of someone in her early 80s. Although her body resists most activity, she still knits, whittles and practises the organ. She has the kind of Yankee disposition that takes things as they come. For her, cancer is akin to a shopping centre going up next door: inconvenient and unexpected, but there's not much you can do about it. She has never listened to Deepak Chopra, switched to almond milk or meditated. Yet she is here, in the chair by the window in the house she was born in, outliving her husband and siblings and nephews and friends.

My father and I visit her about once a year. I ask her thoughts on current events ("Obama seems a nice kid and handsome to boot") and the history of her house ("One toilet and five kids; it was a goddamn joke"). She uses the expression "not in a dog's age!" the way millennials say "like". My father, beholding a woman with the same matter-of-fact staccato and cap of white hair as his mother, becomes withdrawn, childlike. He shuffles his feet the same way he does at his mother's grave or in traffic court, all traces of radicalism gone.

Doad wrote a memoir. Seventeen years ago, when she was already pretty damn old. She chronicled life in her town in the early part of the 20th century – the first car, the first television, the first divorce. She wrote about the one-room schoolhouse, her lone black friend, and the time her brother climbed on a ladder in a devil mask, peered into her bedroom window, and scared her so badly she wet herself. She did it not for glory but for posterity – spare, practical prose designed simply to get the information out, to prove that she was there and is still here. She's proud of the fact that, at her age, she doesn't need help to dress – plaid shirt, nurse's shoes, pastel "dungarees".

The last time we visit, she gives us a pile of scarves she knitted by hand, all slightly too short, the stitches uneven and lumpy. When we leave she says we didn't stay long enough, and we promise we'll be back, next time with my sister. We hug goodbye, and I can feel the curve of her spine, each vertebra bulging.

On the ride back to the city, my father and I encounter some of the "most hideous" traffic he has ever seen. We creep along the highway, and he relaxes his grip on the wheel, grows contemplative. "We should visit Doad more," he says. "She knows we only stay for 45 minutes. She's not senile."

I try something new out on him, something I've been thinking, or wondering whether I think: "I'm really not afraid to die," I say. "Not any more. Something's changed."

"Well," he says, "I'm sure your feelings about that will continue to evolve as you get older. As you see more death around you and things happen to your body. But I hope you always feel that way."

I know he loves talking about death. It just takes him a second to get warmed up.

"You know," he says, "it just can't be a bad thing. Because it's everything."

We talk about enlightened beings, what it would mean to transcend the human plane. "I want to be enlightened, but it also sounds boring," I tell him. "So much of what I love – gossip and furniture and food and the internet – is really here, on Earth." Then I say something that would probably make the Buddha roll over in his grave: "I think I could be enlightened, but I'm not in the mood yet. I just want to work the death thing out."

We crest a hill in the wet dark and see, before us, a string of cars, lit up red, at a standstill as far as the eye can see. We're hours from home. "Holy shit," he says. "That is fucking insane. Is this even real?"

*Doris Reynolds Jewett died peacefully on 10 December 2013, having recently drunk a martini.

• This is an edited extract from Not That Kind Of Girl, by Lena Dunham, published by Fourth Estate at £16.99. To order a copy for £12.49, with free UK p&p, call 0330 333 6846, or go to theguardian.com/bookshop.