I've had to do it a few times. We had a dog Jade we rescued as a puppy. She was mainly German Shepherd. The average life expectancy for German Shepherd is around 10-12. She turned 14 and her health really started to go downhill. She had arthritis and cataracts, she started to have accidents. Then, she didn't want to eat much. She hung onto life despite all that. So, we had to make the decision to euthanize her. She no longer had quality of life.
Prior to that, we took in an older cocker spaniel, Mr. Jack who basically was brought back to life when he came to our house. I have no idea how old he was exactly, but he was old. He had a good almost two years with us, but then his kidneys and heart started to fail. He was hospitalized for a few days, but not improving. We talked it over with the vet and he agreed Mr. Jack wasn't going get better and euthanasia was the most humane option. Like Jade, he was stubborn and held onto life with everything he had. The same vet had seen him when we first took him in, full of ticks and with ingrown dewclaws. He'd always thank us for taking in that old guy. He was quite the personality. Everyone was drawn to him. When I would walk him, female dogs would follow him around and people always wanted to pet him. Even at the clinic, people would stop by his kennel to pet him.
The last was a cat, Loca, who had feline leukemia. She went into kidney failure at about 8 years old and there was nothing to be done, according to the vet.
It's sad, but it can be for the best if the animal has poor quality of life and is suffering.