Generally, the person that has bet last has to show their cards first. So if everyone checks on the river, the person who bet the turn has to show first. In a limped pot that is checked all the way to showdown, the big blind has to show first, since he made the last bet. This "last bet person" is obligated to show their cards. Every other player after that guy doesn't have to show their cards. They can if they want, but they are not obligated to. If they think they are beat, they throw their cards into the muck. This continues clockwise, starting from the first person who showed the cards, until every person has either mucked or shown.
These are the rules in most casinos, the rule who has to show first differ from place to place however. Some casinos (it doesn't occur often) have the rule that the person who is sitting the most left to the dealer has to always show first or that the person that has to act first post flop always has to show first.