My first 401(k) started in the early 1990s with some employer matching funds. Since then, there have rollovers, more 401(k)s, and lost records. Aside from a really rough estimate, what happens when the 401(k) cost basis is unknown?
Unless you made after tax contributions your basis is zero and all distributions are taxable income. If the cost basis is unknown it would be treated as if it were zero. Relatively few 401(k) plans allow after tax contributions and its likely that you would know if you had made them.
I’m referring to after tax contributions to a traditional 401(k) plan not designated Roth contributions. After tax contributions are allowed and would mean the earnings on those contributions would be taxable as ordinary income when withdrawn but the original contribution would not be.
A 401(k) plan is a qualified retirement plan. This means that as long as you follow all the rules and only roll funds to other qualified retirement plans, you don't need to worry about the cost basis of any purchases, because you won't pay any taxes on any of the investments (capital gains, etc.) while your money remains in those qualified plans.
As quid mentioned earlier, you will only pay taxes (depending on the type of plan) when the funds are withdrawn, not when individual investments are bought or sold. (Nor when dividends are paid.)
The special rules that you want to pay attention to with these qualified plans are related to contribution limits, rollovers, and especially withdrawals. Those rules are amply covered in other answers here, but you should become familiar with the advantages and disadvantages of each type of plan.