We study the welfare effects of social security in an overlapping generations general equilibrium model with aggregate and idiosyncratic risk. Prior research on social security has only considered either aggregate or idiosyncratic risk. We show analytically that the aggregate and idiosyncratic risks interact due to the life-cycle structure of the economy. This interaction increases the welfare gains of a marginal introduction of an unfunded social security system. Adding a second interaction by making the variance of the idiosyncratic risk countercyclical further increases the welfare gains. In our quantitative experiment, raising the contribution rate from zero to two percent leads to long-run welfare gains of 3.5% of life-time consumption on average, even though the economy experiences substantial crowding out of capital. Approximately one third of these gains can be attributed to the interactions between idiosyncratic and aggregate risk.