A useful trick to remember is that they're awarded in the
reverse order to what they were created in.
For the sake of the argument let's say these four players all get all in preflop:
A - 1500 chips, holds 7s8s
B - 2300 chips, holds AhKd
C - 2000 chips, holds 9s9h
D - 5100 chips, holds AsQc
The main pot has 6000 in it. A, B, C and D are all eligible to win it.
The first side pot has 1500 in it. Only B, C and D are eligible to win that one.
The second side pot has 600 in it. Only B and D can win that one, and B gets back the 2800 that nobody else in the pot can match.
The board comes 2s Qs Td 5s 3c. You then award the pots in
reverse order, so you start with the second side pot.
Player D has a pair of queens, which beats B's ace-high. D takes the second side pot with 600 in it, and B is eliminated (assuming it's a tournament).
Next is the first side pot. D's pair of queens beats C's pair of nines, so he takes the 1500 pot as well and C is eliminated.
Last is the main pot, which all players were eligible for. A's flush beats D's pair of queens, as well as everyone else's now irrelevant
hands, so he takes the 6000 in the main pot and continues playing.
Note that this hand could have gotten all kinds of messy if the main pot had have been awarded first. Award the pots in reverse order (from the one with the least players eligible for it to the one with the most) and it should always make sense.