A pot can only be won by the players contributing to it. In a pot of three or more players where one is all-in, the all-in player is only eligible to win money that was bet up to the time that he went all-in (this is the main pot). After this player has gone all-in, any bets which occur between the other players are placed in a side pot and can only be won by these remaining players. If the best hand overall (at the end of the game) belonged to the player who went all-in, that player can only win the main pot, as that's the only one they had contributed to. The side pot is then won by the person with the best hand out of the remaining players. If the best hand overall belongs to someone contributing to the side pot, they win everything.