If business titan Peter Thiel’s $5 billion tax-free individual retirement account has you jealous, here’s a way to build a pot of tax-free retirement savings without paying much in taxes: A mega-backdoor Roth conversion.

According to investigative news site ProPublica, over the past two decades, Mr. Thiel, a founder of PayPal Holdings, Inc., turned less than $2000 of pre-IPO shares costing less than a penny each into $5 billion, a gain that accrued tax-free in his Roth IRA. If the 53-year-old refrains from taking withdrawals until age 59 ½ or older, that money can be shielded from tax forever.

Most people won’t ever get a chance to own pre-IPO stock. But the mega-backdoor Roth conversion strategy is available to many people with 401(k) accounts, so long as they have the means to save significant amounts of money. It lets those in 401(k) plans that allow after-tax contributions put up to $58,000 a year into a 401(k) account and convert some or all of the money to a Roth, with a minimal tax hit if executed well.

That vastly outstrips the $6,000 most people are permitted to put into a Roth IRA this year and the $19,500 annual limit on Roth 401(k) contributions. (Those levels rise, respectively, to $7,000 and $26,000 for those 50 or older.) The “mega” strategy also allows individuals with modified adjusted gross incomes of more than $140,000 a year—or $208,000 for couples—who would ordinarily be barred from contributing to a Roth IRA to get money into one.

“You could really see your Roth IRA grow exponentially this way,” said Ed Slott, an IRA specialist in Rockville Centre, N.Y. “The best place retirement money can end up is in a Roth account, where it grows totally tax-free for the rest of our lives.”

In order to take advantage of the “mega” strategy, you have to work for a company that lets employees make after-tax contributions to its 401(k) plan.

According to a survey of 263 employer-sponsored retirement plans by 401(k) record-keeper Alight Solutions LLC, which counts many Fortune 500 companies among its clients, about half offer the option to make after-tax contributions.

Vanguard Group says about 40% of the 4.7 million participants in its 401(k) plans have access to after-tax savings. Of those, 10% have made such contributions. Fidelity Investments says more than 90% of the 19.5 million participants in the 401(k) plans it administers are eligible to make after-tax contributions.

To minimize taxes, it’s best to quickly move after-tax 401(k) contributions into either a Roth IRA or a Roth 401(k) account—something your plan also has to allow.

The mega-backdoor strategy rests on a little known fact about 401(k) plans: the Internal Revenue Service lets employees set aside up to $58,000 a year in a 401(k) account, a number that rises to $64,500 for those 50 or older.

Employees can contribute up to $19,500—or $26,000 if 50 or older—to either a traditional pretax 401(k) or a Roth 401(k). (If offered both a traditional and a Roth 401(k), employees can choose one or the other or put some money into each.)

With a traditional 401(k), account holders generally get to subtract their contributions from their income, reducing taxes. Instead, they must pay ordinary income tax on the money when they withdraw it, typically in retirement when many are in a lower tax bracket.

With a Roth 401(k), people instead contribute after-tax money, foregoing a tax deduction. The money grows tax-free and contributions can be withdrawn tax- and penalty-free. Earnings can also come out tax- and penalty-free, provided the account owner is 59 ½ or older and the Roth has been open at least five years. (Unlike with a Roth IRA, employees with higher incomes can contribute to a Roth 401(k).)

To get to the $58,000 annual 401(k) contribution limit, a worker who has already funneled $19,500 into a pretax or a Roth account can then make an additional after-tax contribution to the 401(k) of as much as $38,500.

The strategy is most effective when an employee can withdraw his or her after-tax contributions soon after making them, pay income tax on the earnings, and convert the money to a Roth IRA or Roth 401(k), where it can grow tax-free.

The goal, Mr. Slott said, is to do the conversion before the $38,500 contribution has a chance to appreciate by much to minimize taxes.

The key is understanding what your employer’s 401(k) plan allows. Be sure to ask whether it lets employees either roll their after-tax savings over to a Roth IRA or convert this money to a Roth 401(k).

Many 401(k) plans allow employees who are 59 ½ or older to roll over their savings tax-free to an IRA, even if they continue to work for the company.

SHARE YOUR THOUGHTS

What does your employer’s 401(k) plan allow? Have you taken advantage of it? Join the conversation below.

Like people of any age who leave a company, these older workers can convert their after-tax 401(k) contributions to a Roth IRA, while simultaneously funneling their pretax savings—plus the earnings on their after-tax contributions—into a traditional IRA, said Ian Berger, an analyst at Mr. Slott’s company.

Some plans allow workers younger than 59 1/2 who continue to work at the company to withdraw only their after-tax money, which makes it possible for them to convert it to a Roth IRA.

Among the growing number of companies that offer Roth 401(k)s, some allow employees to convert after-tax 401(k) contributions to a Roth account, said Mr. Berger. Three-quarters of the 401(k) plans Fidelity administers offer a Roth 401(k) option.

Government 457 plans don’t allow after-tax contributions, said Mr. Berger. The same is true of many 403(b) plans, retirement savings plans that are typically sponsored by nonprofits and schools.