The answer is much simpler than you might have thought!
The distinction between using "whom" or "who" in a sentence is a matter of determining whether that third party is the subject or the object of the sentence.
To recap, the subject in a sentence is the acter -- the doer -- the one that is performing an action or doing something. For example, in the sentence "Peter threw the ball," the subject is
Peter because he is performing the action of throwing the ball.
The object of the sentence is the thing that is being acted upon -- either being manipulated, moved, addressed, transformed, etc. So in the sentence "Peter threw the ball" the
ball is the object of the sentence, because the ball is the thing being acted upon (thrown) in the sentence.
Now onto your question:
In a sentence, use "who" if it describes the subject of the sentence. For example:
"WHO is playing tonight"
"WHO wants dessert?"
"The folks WHO just left the restaurant did not pay their bill!"
Conversely, use "whom" when it refers to the object of the sentence. Note that this includes the object of a preposition ("under", "over", "behind", "between", etc.)!
"To WHOM would you like to speak?" (subject is you, preposition is
to, object is whom)
"I can't remember WHOM I went to the bar with last night." (preposition is
with, object is whom)
"You were sitting right behind WHOM at the basketball game?!" (preposition is
behind, object is whom)
I know the usage of "whom" might sound a little strange, but techinically it's correct.
So remember: In a sentence, the subject ---> "who". The object (including the object of a preposition) ---> "whom".