This is something I struggled with myself, as I watched my rat terrier grow older and older.
He started losing his hearing at 13, so I taught him hand signals for the commands he knew---and also, one for "I love you", which would bring him close to me for a cuddle.
He started losing his hearing at 14, and by the time he was 16, was completely deaf, and could see very little. He learned to bump his way down the hall to the sunny spot in the kitchen, by walking in a sort of zig-zag, touching the walls with his shoulders to navigate. Sometimes, I'd find him standing in the hall, staring at a wall, and knew he thought he was standing in the office, staring at me, waiting for me to take him outside.
Through all this, I wondered, how will I know when it's time? My friends all told me that I'd know, but honestly, I didn't. Was I being selfish, keeping this poor little guy beyond his time, letting him live on without sight or hearing?
Then, one morning, I knew. I went to get him from his basket, and he'd wet himself. I picked him up, and carried him outside, and he collapsed. He couldn't stand up, and it was clear that one side of him was weak. I knew he'd had a stroke, so I called the vet, and asked to bring him in.
My vet was very gentle with us, as she explained what had happened, and outlined all the options. Dogs can come back from strokes, just like people---but, realistically, a dog who was just short of 18, with no sight or hearing? I just didn't see how we could help him recover, and so, we made the hard choice to let him go.
I really think my friends were right. When the time came, I knew. Even before I called the vet, I knew. I held my little guy for hours before taking him in, and I'm not sorry for making the choice I did. It was obviously his time, and it wasn't right to try to prolong his life further.