In retirement plans you deposit money into an account which is saved (and invested) for when you retire.
I thought all pension plans work that you are paying out to current retirees
When a pension is set up, reserves are held in safe investments to pay future liabilities. If those reserves prove to be insufficient, the company that set up the pension is still on the hook for any shortfall. The risk to the company is minimized in the same way as other life and annuity products - by pooling it among the participants - which is why those are all considered actuarial fields.
The difference with social security is that the 'reserves' for the pension are incoming tax revenues and to a lesser extent interest from treasuries being held for social security.