Suppose both you and a partner get arrested whilst trying to rob a bank. Without a confession from one of you, the police can only convict you of a minor offense (say trespassing).
The police place you in different cells, and offer you both the following bargain. If you confess to the robbery, and your partner does not, you get a complete pardon, and your partner gets a full sentence (say 120 months in jail). If you both confess, you get a slightly reduced 100 months in jail. Finally, if you both remain silent then each gets a 3 month sentence for trespassing.
You both now have this tension between individual and collectively optimal action. Your personal sentence is smaller (independent of what your partner does) after confessing, but you both benefit from coordinating to not confess. You can draw the payoffs in a matrix (left is row player and right is column player) to visualise this.
c c'
c 100,100 0,120
c' 120, 0 3,3
This tension applies to lots of other interactions (e.g. firms colluding to restrict output, communities collaborating to maintain public goods, neighbours not pissing each other off by throwing massive parties).Even if there is a repeated interaction for a finite amount of time, you can expect rational self-interested agents to be unable to collaborate in the final period. This means they have no way of punishing in the penultimate round, and so by induction you would expect 'unravelling' to non-cooperation right from the beginning.
This paper found that a subset of the population appearing not to be self-interested was sufficient to prevent this complete unravelling. Even a selfish player may wish to collaborate in early interactions if there is a high enough chance that they won't be immediately punished.