1) no one likes to be an afterthought.
2) you usually have to go all-or-nothing.
#1 - means, simply, don't plan a gathering, then call your buddy Sue two hours into and say, "Hey, we're all hanging out here...why don't you stop by?" Even worse is a text to Sue. Really, please, show her how little she means to you.
#2 - certain situations can be tricky. You're getting married, or having a plain-ole' party, and you like Jim, Sally, and Dave from work, but you'd hate to have (shudder)Kris or Beth attend. What to do?
The answer lies above. Due to office politics, and your urge to avoid hurt feelings and at-work snippiness, it's best to either invite no one, or all of 'em. Your other option, if it's well played, is to take your few work buddies off to the side, invite them verbally, and mention that "not everyone from here is invited." If they can keep shtum, you're safe. But if word goes around that 50% of your office is invited (and the rest aren't), well, be prepared for some yucky feelings.