For the young Sarah Silverman, sleepovers were hell, school camp a nightmare. Why? Because until she was 16 she regularly wet the bed. The comedian writes of the shame, the soaked sheets and the plus-sized nappies that haunted her childhood

On 16 August, 1977, Elvis Presley saved my life. The previous afternoon, I played with my six-year-old peers in Heather Peters' backyard. I was blissfully helping myself to pizza and cake when Heather asked me where my sleeping bag was. Heather explained – because I had somehow missed, or perhaps wilfully ignored – that this party was a sleepover. Fuck me, this is a sleepover?

It's helpful to mention, at this point, that I was – and would be for many years to come – a chronic bedwetter. The word "sleepover" to a six-year-old bedwetter has roughly the same impact of, say, "liver cancer" to a 40-year-old alcoholic. The moment the word is spoken, gruesome images of your near future flood your mind. At least with liver cancer, people gather at your bedside instead of run from it.

I had one reliable means of escaping these situations. I'd explain that I needed my mother's permission to spend the night. I'd call her from somewhere with sufficient privacy, then rejoin my friend with the bad news that my mom wouldn't let me sleep over. But Heather eagerly stood next to me as I called Mom. Like a hostage with a gun at her temple, I put on an act to satisfy my captor. I "pleaded" with Mom to let me stay over, and, not detecting my insincerity, she granted permission. "Of course, Sweetie. Have fun."

Here's one tip to bedwetters or parents of bedwetters: have a codeword or phrase. So if your child calls and says, for example, "Your package from Zappos is on its way", or, "The man from Moldova wants more lemons", or just "fuzzy dice", you'll know your child is in danger of pissing herself in someone's house, and you should order her to come home at once.

I hung up, turned to Heather, and harnessed the momentum of my plummeting heart to sling it upward into a joyous, "She said yes!!" It was settled. I would be sleeping in the same living room as Heather and about eight other girls. By this age, I'd peed myself on numerous sleepovers, but here was a chance to do it with a substantial audience.

The anxiety of the impending night took over. I felt like a zombie, going through the motions of a child at play. I didn't bring my own pyjamas or linens, so Mrs Peters provided me a sleeping bag and a pair of Heather's way-too-sexy-for-a-six-year-old pyjamas. They were harem-girl bottoms with a short cropped matching top. The anxiety of being in Heather's stuff was stress-gravy on an already terror-filled plate. As the other girls drifted into their sweet little dreams, I pinched myself awake, constantly testing my bladder. "Do I need to go again? I'll stay up to go one more time …" Of course, if you battle against sleep this ferociously, when it finally conquers you, it takes you down hard.

The next morning, I'm the first to wake up. I am warm – which is a trick on people like me. I can stay in denial, lying perfectly still in the warmth, or test it, by moving just the tiniest bit. I venture, rocking my body just slightly to the right. Ice-cold air whooshes along my body and I freeze, heartbroken. I lie, motionless, in panic and urine, for what seems like hours before the other girls start to wake up. I do the only thing a terrified zombie can do: I pretend it didn't happen. I get up with the other girls, take off my PJs like the other girls, and change into my clothes. They're so lucky to be able to move through life so effortlessly. I know at six how lucky they are – they probably still don't know.

Mrs Peters walks into the room, and before she can say anything, steps right on to the pile of my sexy urine-soaked pyjamas. My heart stops as I watch her face burn red like a Disney villainess.

"Who did this!?!?!" she screams, with a look of pure fury. I stand there, quietly enduring the world's youngest heart attack, wishing for my fear to somehow transport me. Am I supposed to answer? Is the onus on six-year-old me to fill this silence? And that's when it happens – Mr Peters comes in and grabs his wife, "Elvis Presley died!!!"

The news of the King's death overtook Mrs Peters, and I was spared. Somehow I got home without the other kids knowing what had happened.

By eight years old, my urine showed no promise of abandoning its nightly march out of my urethra and on to my mattress. New Hampshire was running out of clean sheets. All the doctors could offer was a diagnosis of enuresis – meaning my bladder was too small. I was tiny for my age, there was no medical cure but to grow.

Girls were getting tits and periods, and I had seemingly plateaued, elementary-sized. My parents worried, but I also think there was something about me being so small that felt right to us. My dad would always say, "Keep passing the open windows." I didn't know what he meant until he explained that in John Irving's Hotel New Hampshire, there's a girl who never grows. She becomes a revered novelist but eventually kills herself by jumping out of a window. Until then I had never thought of open windows as the opportunities for suicide they truly are.

I realised I was going to be a bedwetter for the rest of my life. I supposed maybe someday this nightmare would end, but even so, you're always an alcoholic, right? Even if you're living dry? To still be a bedwetter in high school, to have a condition this deeply entrenched, is a pretty serious problem for a child.

I was elected student leader of our school's annual camping trip, which I was proud of but extremely nervous and anxious about for a couple of reasons: 1) I was a bedwetter. This is going to be tricky, and 2) did I mention I piss in my sleep?!

In the last month of my 12th year, my mother helped me hide three diapers in the bottom of my sleeping bag and sent me off to go lead my fellow students camping. We were loaded on to the bus and on our way. When we got there, we lifted our gigantic packs on to our backs and up the mountain we hiked, led by me. I don't even think it was an hour before I started sobbing. When the teachers asked why I was crying, I reached for a more stoic answer than the truth.

"I'm worried about my mother being alone without me."

"Aw, I'm sure your mom will be just fine," the teacher said.

"No, she won't! You don't understand," I said, figuring broad and nondescript might be the way to go with this.

As we set up our tents it started to pour, and after eating our smoky, fire-burned dinner, we went to sleep. Surrounded by my tentmates, I subtly reached to the bottom of my sleeping bag with my toes and took care of business without incident, probably because, in their wildest dreams – among the giggling and gossip and talking about boys – they would never guess that one of us was wearing Pampers.

Our bus pulled into the school parking lot after our long journey. The kids hopped off to be met by their parents. I saw my mother, waiting with the other moms, smiling. I was suddenly overwhelmed with shame. I was so embarrassed by my behaviour that first day of the trip, and seeing my mother made it real and permanent. This pain was compounded by the fact that with each step of the bus I descended, Mom was snapping pictures of me, the flash illuminating my shame from the inside out. I begged her to stop, but like a shuttering paparazzo she ignored me while continuing to take pictures. It's a bizarre way to be ignored.

As I walked to the car, enduring Mom's relentless camera flashes, a wave of… something… washed over me, and instantly transformed who I was. It happened as fast as a cloud covering the sun. It was at once devastatingly real and terrifyingly intangible. I felt helpless, but not in the familiar bedwetting sense. As quickly and casually as someone catches the flu, I caught depression, and it would last for the next three years.

Everything about who I was changed. Until then, I'd been hooked on telling jokes. Chasing laughs. When I was three years old my father had taught me to swear like he was teaching a "cursing as a second language" course for one. I soon learned that just saying "I love tampons" or any shocking non sequitur was rewarded with frenzied laughter. The approval made me dance like Snoopy. The feeling of pride made my arms itch. It fed this tyrant in me that just wanted more more more, push push push.

I had always been able to turn pain or discomfort into humour, but that trick was gone now. I couldn't relate to ever knowing it. I stopped being social. The thought of seeing my friends felt like a burden. All I could focus on was that I was alone in my body. That no one would ever see through the same eyes as me, not ever. It filled me with a loneliness that only deepened when I was not alone.

My parents sent me to a therapist. He was an old man whom my dad had seen give a lecture somewhere about working with kids dealing with divorce. Even though by this point my parents had been divorced for six years, my father figured my sudden depression was most likely a result of it. Who knows, maybe he was right? I walked into the therapist's office, and he had two chairs set up, facing each other. He had me stand with one foot on each chair, explaining that one represented my mother and the other, my dad. As I stood, he pulled the chairs farther and farther apart until I couldn't balance without jumping entirely to one chair or the other.

"I love them both!" I yelped, as I fell forward and off both chairs in defiance.

When Dad picked me up after the session, I told him what had happened, and it was back to the drawing board. The next therapist seemed to have more promise. He was a psychiatrist, and that's like a real doctor. I described how I felt and he said, "Sarah, I'm going to write a prescription for a medicine called Xanax, and I want you to take one whenever you feel sad." I was 13.

By the time I was 14, I was taking four Xanax four times a day. Sixteen Xanax per day total. Although I never said it out loud, in my heart I thought, This cannot be right, so I saved each empty prescription bottle in a shoebox in my room as evidence if anything happened to me.

In my first year of high school I missed three straight months in a row. I just couldn't go to school. I was paralysed with fear. It was unbearable to be among other kids who were just standing around being fine. It was one of the many inconveniences of this paradox I lived with – the more people I was surrounded by, the more frighteningly alone I felt.

My stepfather, John O'Hara, was the goodest man there was. He was not a man of many words, but of carefully chosen ones. He was the one parent who didn't try to fix me. One night I sat on his lap in his chair by the wood stove, sobbing. He just held me quietly and then asked only, "What does it feel like?" It was the first time I was prompted to articulate it. I thought about it, then said, "I feel homesick." That still feels like the most accurate description – I felt homesick, but I was home.

The thing about depression is that, if you're not the one who's suffering from it, there's very little you can do to be proactive. If someone in your family is depressed, all you can really do is send them to the shrink, get them their meds, be gentle, and wait. A persistent bedwetting problem, however, is a call to action. Surely there must be a way to stop a small amount of liquid from moving a short distance during a certain time of day. It's a very tangible, physical problem. A science project, really. Combating my depression was a job for an army of geniuses. But the solution to my bedwetting problem, Dad still believed, was within his grasp.

It really killed Dad that I couldn't stop wetting the bed. He was a bedwetter as a kid, too. And, his father, too. For a while I had to wear diapers to bed. That way there was no messy changing of the sheets. It was humiliating, but I got used to it. Plus, it was convenient. But it was just a Band-Aid, and Dad wasn't about to give up on me.

He put an electric pad under my sheet, designed to set off an alarm when moistened. Though "alarm" doesn't really do it justice, I'd call it more of a shocking, heart-attack-causing scream.

That first night of the screaming aluminium sheet was the last night I slept at my dad's house. I mean, I still spent the night as the joint-custody schedule dictated, but I didn't sleep. The horror of waking up to that stunning alarm kept me up most of the night, or until my body couldn't fight it any longer – and you know what happens then: total submission, and all it entails.

I was sent to another shrink. When I told him I was taking 16 Xanax a day, he was horrified. He called my mother in and told us that this was fucked-up shit (I'm paraphrasing) and that his very own brother died going off Xanax cold turkey. He explained that I would go off the Xanax gradually, a half a pill less each week. It was eight months before I was completely off meds – and the day I took that very last swallow of half a Xanax was the happiest day of my life to that point.

I finally grew, bladder and all. Around the time that I got my driver's licence, and the final traces of Xanax left my system, and the cloud of depression lifted, my enuresis went away. Just as the doctor had predicted, more than a decade before.

I was a late bloomer all around. My period came late, my ability not to go off like a fucking lawn sprinkler every night came late, and sex came late. Essentially, everything having to do with the general flow of traffic in my vagina came late. Ironically, I was this girl in high school through whom everyone came to learn about sex, though I, myself, had never gone past kissing a boy.

And then, in the summer before my last year of high school, I had my first experience of live comedy. I'd never been inside a comedy club before, and I was underage, but somehow I weaselled my way in. As I entered, I heard a woman's voice on the mike. It was Wendy Liebman, who at the time was an emerging talent but would go on to become a major comic. Each joke she told was funnier than the one before it. I was blown away. I found out when the next open mike was and signed up.

My first set was pretty successful. I told some jokes about high school and ended the gig with a song about being flat-chested, which at the time I was. I was not especially nervous. It might be that I'm one of those people who are naturally comfortable on a stage. Or maybe my lack of stage fright was the upside of years of nightly bedwetting. Maybe that daily shame had ground away at my psyche, like glaciers against the coastline, so that somewhere in my consciousness, I understood that bombing on stage could never be as humiliating. My early trauma was a gift, it turned out, in a vocation where your best headspace is feeling that you have nothing to lose .

• This is an edited extract from The Bedwetter, by Sarah Silverman, to be published by Faber & Faber on 2 September, priced £12.99. To order a copy for £11.99 with free UK p&p go to theguardian.com/bookshop.