That said, these machines aren't perfect. You'll almost always get a bit of gear slippage. It's so common it feels silly to mention it, but just in case you've never noticed gear slippage, here's a trick.
When you need to tune a string down, always do this: work the tuning machine so the string goes flat – flatter than you want it – and then slowly tune back upward until you nail it. This will ensure you've dealt with gear slippage in the machine. It'll happen every time you tune down. Go further down and back up. That's it.
I've tried that, but my feckin guitar still won't stay in tune. Stop yelling at me. Stable tuning doesn't begin and end with the tuning machines. The next thing to consider is the nut. If the slots are too thin they grip the string, and you don't want that. You've probably heard the dreaded ping. Just when you think you're about to get the note perfect, there's the ping, and the note flies sharp. This is the string getting hung up in the nut: too much friction. A healthy guitar has even tension all along the string: from the machine, through the nut, right down over the saddles and into that hard tail we talked about.
You're a filthy liar, I don't have any of this stupid ping nonsense and it's still going out of tune. Well I never. If the guitar is in good order, then it's time to swallow the most bitter of pills: it's you. Your stringing technique is letting you down. I sound like a broken record here, but it's all about tension. When you bend notes or play hard, you increase string tension momentarily. Those increases shouldn't be a problem. Strings are elastic, and they should return to pitch. The problem arises when that momentary extra tension has access to available slack.
Take a look at this Tele. Too much slack leaves room for the string to nestle into the winds. Don't do that.
But BB King used to wind his whole… Stop it. You're not BB King. And don't do the opposite. Too few windings around the post means the string won't have enough grip. The post will stay exactly where it is, but the string will slip slowly out.
When you change strings, don't rush. Take time to guide the strings onto the post while you wind them, ensuring they have ample grip, but don't bunch up.
Right. I've done everything you've said, and it's still going out of tune. It's possible I'm going to kill you now. So angry. But listen, there's an old adage: new strings always go out of tune. It's true they need to settle. Some say this takes time. It does, but that's really vague. You can shorten this time by stretching in the strings. Once you're strung, and at pitch, tug on the string to stretch it in, and retune. Have your guitar plugged into to a tuner to see just how far out the pitch goes. Do this a few times for each string until they keep their tune within a few cents. If you've never done this before, there's a chance you'll go too far and break a treble string, but that's all part of the learning process. If you think this is going to happen, wear safety glasses.
Musicians should never shy away from the mechanics of their instruments. Just because you're an artiste doesn't mean a bit of physics is beyond you. Give this stuff a whirl, and enjoy. Your audience will appreciate you for it. You'll inflict less dead air on them, tuning between songs.