Basically, these plans defer income taxes, but they do it in various ways. Sometimes contributions are deductible, and sometimes not. Earnings in the plans are not taxed until withdrawal. Even though investments usually are sold when a withdrawal is made, no capital gains taxes are due, only income taxes. The exception is the Roth IRA, in which you pay no taxes on accumulated earnings at any time.
Some plans also permit non-deductible contributions.
You can roll over a 401k directly to an IRA without paying taxes when you leave your company. You also can convert an IRA to a Roth IRA, but you must pay taxes on all contributions and earnings at that time. The government has laid some land mines to possibly boost taxes on these plans.