Sometimes you can tell what a pronoun refers to by the number and/or sex.
Example 1: "Bob and Sally drove to the market in his car." "His" here must refer to Bob and not Sally because "his" is masculine, Bob is masculine, and Sally is feminine. So "his" matches the gender of Bob but not of Sally. (One could quibble that I am assuming that "Bob" is a man and "Sally" is a woman. It is, of course, possible that Sally is a man. But not very likely, and unless in context we are told that Sally is a man, readers would normally assume that she is a woman.)
Example 2: "The people in the crowd booed when the actor gave his speech. Then they threw rocks." In the second sentence, "they" must refer to "the people in the crowd" because it is plural and "the people" is plural. It can't be the actor who threw rocks because "they" is plural but "actor" is singular.
Besides that, you have to rely on logic and context. Like suppose I read, "Bob and the dog entered the house. 'Hello', he said." I'd normally assume that "he said" refers to Bob and not the dog, because dogs can't talk. (If this sentence occurred in a story about a talking dog, then it would be unclear.)
People sometimes -- often -- say or write sentences that are unclear because such references are ambiguous. When the person is saying the sentence, he knows that when he says "he" he means the tall man with the red hat (or whomever), but he fails to make that clear to the listener.