It seldom happens for me because I typically stay up a lot later than most of our friends. Our friends typically have to be at work by 7 or 8, where I work for myself and more or less keep whatever hours suits me.
On the rare occasions I do need someone to leave I just tell them that I need to go to bed and have to throw them out.
Since I'm the one who stays up later than others I'm more normally keeping an eye out for cues that it's time for me to leave, and the people I hang out with most know they are free to just say it straight if they need to go to bed. One friend of mine does that fairly often - I know what sort of time he usually wants to be thinking about winding down and heading to bed but sometimes if he's hard a hard day he is ready to sleep earlier than normal.