It wasn't until just before graduation that we talked about what to do when a patient is dying. A single three-hour seminar with a group of specialists from the palliative care service; at least it was mandatory.

The presenters were young physicians, and they seemed kind and thoughtful. But I wondered why anyone would devote their medical career to end-of-life care. My classmates and I had spent years of medical school sharpening our history-taking skills, learning to recognize heart murmurs, memorizing the drugs used to treat high blood pressure, diabetes, even cancer. In the final months of school, I'd worked in the ICU, taking care of critically ill patients who required breathing tubes and life-sustaining machines. I'd learned how to perform intubations and place central lines. I marveled at how much I was able to do to help sick people. Nearly all of us became doctors to keep patients alive, to treat them.

I thought: The ultimate treatment failure is death. I graduated medical school and moved on.

Except for a cadaver in my first-year anatomy lab, I didn't see a dead body until the second month of my medical internship. When I finally did, it was my first overnight shift; I was the sole intern charged with cross-covering all of the medical patients. The pager never stopped beeping. I handled issues as they arose. I solved problems. But at some point in the night, a nurse called and said I needed to "come pronounce room 556." My heart sank.

I wasn't precisely sure what pronouncing a patient dead entailed. When I reached room 556, I entered to find a frail woman lying still on the bed. Mrs. Lee. She was surrounded by family members young and old, and, to my amazement, they were smiling, chatting, even laughing with one another. I mumbled a greeting, then crossed to the bed, where I proceeded shakily through the pronouncement checklist in my intern handbook.

For 30 minutes I watched strangers in masks and gloves race around an unconscious old man, trying everything they could to keep him alive One of Mrs. Lee's daughters touched my hand. "This is my mother; she was a wonderful woman but had a long battle with Alzheimer's, and it was time for her to go," she said. "She just wanted to be comfortable in the end."

The other family members nodded in agreement and went on talking about how much they had loved Grandma Lee's custard buns and who would be getting her recipes. Mrs. Lee's family and friends, who had gathered around her to say goodbye, moved me. Mrs. Lee had had the forethought to tell them how she wanted to pass, and they were by her side until the end. I had never before pondered the idea of a "good death," but that night I walked out of room 556 with a smile on my face, because, somehow, I had just witnessed one.

When I was a newly minted doctor, I found myself back in the ICU, no longer a lowly medical student but with real responsibilities.

The patients in an intensive care unit are very sick; they require the highest level of monitoring and intervention that a hospital can provide. This particular unit was lined with patient care bays featuring sliding glass doors, glaring white walls, blinking monitors, and little natural light. Alarm bells dinged constantly, and the smell of bleach disinfectant made my eyes water. I began my rounds each morning at 5, checking in on my patients and learning about those who had been admitted overnight.

One morning, I came in to a commotion. There were several nurses scurrying around a new patient's bed, and the night residents were huddled in a corner, concerned looks on their faces. Before I had a chance to ask what was going on, a loud code blue alarm went off overhead, and the team of doctors descended upon the patient. I peered into the room, and underneath the breathing tube and profusion of lines, I saw an elderly man.

The senior resident called out orders. The intern hopped up on a stool next to the bed and began performing rhythmic chest compressions that cracked the man's ribs. The nurses pushed various medications into his IV and watched the heart monitor intently. I stared at the spectacle in front of me. This was my first time seeing a code situation. For 30 minutes I watched strangers in masks and gloves race around an unconscious old man, trying everything they could to keep him alive. But after the heart rhythm monitor fell into a flat line, the team pronounced him dead, removed their protective garb, and walked out of the room.

I later learned that an ambulance had brought in the old man for decompensated heart failure. His heart could no longer effectively pump blood to his organs, and he had been drowning in fluid that backed up into his lungs. On arrival, he was immediately intubated and rushed to the ICU. His family members were out of town, and he had not come with advance directive paperwork, a document stating his wishes.

This was not his first trip to the hospital. He had been admitted five times in the previous six months. During his first hospitalization, his records showed that he was a "full code" and that family had wanted "everything done" to keep him alive. Despite multiple readmissions, the question was never revisited. I wondered whether they knew what "everything" meant.

I learned that the old man was named Mr. Azarov. He was 88 years old, a widower, originally from Russia, where he had worked as a tailor and musician before coming to the United States. In San Francisco, he'd opened a bakery and had led a simple life. Over the months of his hospitalizations, Mr. Azarov had slowly deteriorated, and each time he became weaker. He battled kidney failure, a stroke, and worsening dementia. Well before he came to us for the last time, he had lost the ability to stand up on his own. His adult children were no longer able to care for him, and several months before he died they'd moved him into a nursing home.

I never knew Mr. Azarov, but I realized then that this man had been dying for a long time. He had a brutal, impersonal end, one he received by default. Who would die that way if they had a choice? Expiring in a hospital room, doctors screaming and scurrying and cracking your ribs, away from your friends and family — I wondered how many opportunities there had been to explain his end-of-life options to him or his family. Did they understand his prognosis? I'll never know. But as he lay there alone in the hospital bed, curtains drawn, still attached to machines, I felt as if we'd failed him.

One day, late in my intern year, while working the emergency room, I met a patient named Mr. Jones. He was a botany professor who lived in an affluent suburb outside San Francisco. He was married, with three grown children, and had the amazing fortune of good health over the whole of a long life. But now he was 72, and he was dying of small cell lung cancer.

Mr. Jones was receiving chemotherapy under the care of a reputable oncologist. He'd come into the ER that night because of severe, worsening shortness of breath that made him unable to walk across the room without collapsing. He told me his family was scared and so was he.

Before coming into the room, I'd reviewed his labs and chest X-ray and found that he had significant bilateral pleural effusions secondary to his lung cancer. This was a bad sign. When I came in, I saw that Mr. Jones had once been fit and brawny, although now he was worn and thin. We talked for a while. I asked the customary questions about his symptoms, and got the sense that he was a kind man. I explained to him that fluid had built up in his lungs due to his cancer, and that while we could admit him and remove the fluid with a needle, it would only make him feel better temporarily. I told him I believed his cancer had progressed.

I felt unusually at ease talking to Mr. Jones. After delivering the news, I decided to venture into unusual territory: I asked him what he understood about his diagnosis and his future. He explained that he had read online how he likely had only months to live, but that his oncologist wanted him to continue chemotherapy for now. Then I asked him what he wanted. To my surprise, he paused. After a moment, he looked up, tears welling in his eyes.

"I've had a wonderful life," he said. "I have an amazing family who loves me, and I want to be at home with them, not here in the hospital." He started crying. He grabbed my hand. "No one has asked me what I want. Can I please go home? All I want is to be home."

We spend almost no time at all learning about illness in the context of a patient's life I was shocked. How could this be? I thought. How had we all failed to take a step back from the diagnoses and treatment options and the lab and imaging results to ask the most important question of all? Mr. Jones did not want to be admitted to the ICU. He didn't want to be intubated and adorned with the lines we use to sustain the dying. He knew there was no cure for his cancer, and he wanted what all of us hope for in the end: to die comfortably. With the help of the case manager and the social worker, I was able to send Mr. Jones home with hospice care early the next morning. I found out that he died in peace, two days later, surrounded by his beloved family.

I took time to talk to this man, to learn about his life and wishes. Together, we decided on a plan that fit his goals for his remaining days. The news of his passing gave me a sense of fulfillment. I felt relief that I had kept him from suffering. I thought back to the medical school seminar, and for the first time I understood why those doctors chose palliative care.

As doctors, we dedicate most of our time in medical school to learning about the physical body, how things can go wrong and how modern medicine can fix them.

During residency, we acquire methods for analyzing large amounts of data so that we can accurately assess, down to the minute, what is happening with our patients.

But we spend almost no time at all learning about illness in the context of our patients' lives, or how to heal people when modern medicine provides no cure. We are rarely schooled in how to break bad news compassionately, or how to sit in silence with a grieving family member, or even how to make recommendations for appropriate end-of-life care.

I have become disheartened by the number of patients who received invasive treatment in the final days and hours of life. So many spend their final moments hooked up to tubes and lines in the ICU, alarms beeping in the background, hidden away from the people who care about them. Modern medicine is always poised to offer another procedure or therapy for prolonging life, but it often does so without considering the quality of that life. How much suffering is five more weeks worth? Or five days, or five hours?

Today's physicians are spread thin. We have more responsibility than ever and are often tethered to a computer screen instead of at our patients' bedsides. Maybe it's easier to just give someone more treatment instead of stopping and telling her that she's dying. These conversations are never easy, no matter how many times you've had them. They can be enormously difficult even under the best circumstances, and often the circumstances are more like a patient (or, more often, his family) arguing, denying what's going on and demanding to see another doctor. Maybe we just don't want to go through it. Or maybe we hide behind more tests and procedures to make ourselves feel better — like we're still fighting. Like we haven't failed yet.

I don't see it that way. I believe we owe it to our patients to have open, honest conversations about what the future holds. Patients and families need to be informed in order to make decisions that are in line with their values.

My patients have all taught me valuable lessons about what a "good death" might look like. Each one has reminded me that there is more to medicine than placing a line to monitor the heart, or performing an intubation. Just because more tests and procedures exist does not mean that we should perform them all each time. Sometimes the most powerful healing of all comes through the simple act of sitting and listening to our patients with compassion.

We know that 75 percent of Americans would prefer to die at home. Only 20 percent actually do. We also know that 80 to 90 percent of physicians would not want CPR or mechanical ventilation at the end of life. Doctors actively choose to forgo the suffering that takes place in our ICUs, because we've seen it and we know better. My goal is to close this gap, to educate my patients about their options based on open, honest communication. I no longer see death as a failure but as a place we are all headed at some point — and if I can help someone live the fullest to the very end, I have practiced the best medicine.

Shoshana Ungerleider, MD, is a hospitalist physician practicing in San Francisco, California. Follow her on Twitter @ShoshUMD or on her website.

First Person is Vox's home for compelling, provocative narrative essays. Do you have a story to share? Read our submission guidelines, and pitch us at firstperson@vox.com.