The word who can only be used when it is the subject of a verb. That might sound confusing, but it just means it is like the words I, he, she, we, and they. Just like who, each of these words can only be the subject of a verb. The difference with who is that some people are unsure when to use who and whom. Well, confusing that pair is no different from confusing these pairs: I/me, he/him, she/her, and they/them.
I have not seen the man who lives in the hut by the beach for a week.
(Who is the subject of the verb to live.)
Whom is never the subject of a verb. (Who, on the other hand, is always the subject of a verb.)
You sat by whom all night?
(In this example, whom is not the subject of any verb. You is the subject of to sit.)
Always use whom after prepositions. (Prepositions are words like to, with, by, on, in, near.)
You have a child by whom?
(by – preposition)
With whom did you see Janice?
(with – preposition)