Fundamentally the same kinds of rules apply when choosing between who and whom as when you are choosing between me, myself, and I. The key concept to take home is the difference between a subject and an object.
Who is a subject form of the pronoun. Who bought the car? Who went to the store? It is used in much the same way as he or she in this regard. He bought the car. She went to the store.
Whom, by contrast, is the object form of the pronoun. It receives the verb, so to speak. Tim was sitting with whom? Christine gave the prize to whom? It is used in much the same way as him or her. Tim was sitting with him. Christine gave the prize to her.
These examples are the simplest, because they make use of those “helper” words: to, with, at, and so on. Even when you think about sentences that end in a preposition, the rule holds up:
Incorrect: “Who is Steve on the phone with?”
Correct: “With whom is Steve on the phone?”
You could stick with having the preposition at the end of the sentence, but true grammar sticklers won’t like that.
It gets more challenging when these prepositions aren’t there, but you still have to recognize that you should be using an object rather than a subject.
Whomever Russell interviews last will need to lock the door.
The reason why we use “whomever” here instead of “whoever” is that we are still referring to an object. Going back to the test of he/him (or she/her, if you prefer), we would say that Russell interviews him (object), not Russell interviews he (subject).
All this said, just like ending in a preposition and writing with split infinitives, the hard and fast rules of grammar are increasingly not so hard and fast. For most of your writing, you can usually get away with a more flexible grasp of rules like these. In formal writing though, you may want to be more careful.