In casual messages with friends or water cooler conversations with colleagues, it might not seem particularly important to use perfect grammar—and saying whom can sometimes make an exchange seem formal in a way that doesn’t match the situation. But there are still plenty of instances when perfect grammar is necessary, like emails to the CEO of your company, published works, or telephone talks with your persnickety relatives.
For those times, Lifehacker has a nifty mnemonic device to help you remember when to use who vs. whom. In short, mentally swap out the who or whom in your sentence with he or him. If he sounds right, you should use who. If him is the obvious winner, go with whom.
This works because who and he are both subjective pronouns; that is, you use them to refer to the subject of the sentence. In “Who let the dogs out?”, the subject of the question is the person letting the dogs out. If you replace who with he there, you get an equally intelligible sentence: “He let the dogs out.” Neither whom nor him would work, because they’re both objective pronouns—you substitute them for the noun that receives the action of the sentence. Since you wouldn’t say “Him let the dogs out,” you shouldn’t say “Whom let the dogs out.”
In the sentence “Whom will you invite to dinner?”, you is the subject, and the person you invites to dinner is the object. Just like in the first example, it’s easier to discern whether he or him works if you rephrase the question as a statement. “You will invite him to dinner” sounds fine (if a little bossy), while “You will invite he to dinner” frankly sounds hilarious.
You can definitely substitute who and whom with other pronoun combinations like she and her or they and them if you’d rather, but the reason he and him work so well is because they sound similar to who and whom—the only aural differences are the vowels.
As a consolation prize for the hassle of having to think about who vs. whom, here’s a grammar rule you probably use correctly every day without even realizing it.