My (potentially flawed) understanding of Roth IRAs is that you can take out contributions at any time without penalty. So if you put $5,000 in and it doubles in a year to $10,000, then you sell some stocks and withdraw $5,000 (or less) from the account, then I can use that $5,000 for anything and I don't have to pay taxes on it (except the taxes I payed before putting it in the IRA). The other $5,000 is earnings, and I would have to pay taxes on it if it were withdrawn before the age of 59.5 (with exceptions).
How is this affected by 401(k) rollovers? Is the money from the rollover also treated as a contribution with respect to the penalties I would (not) have to pay if withdrawn before retirement age? Or maybe just the amount from the 401(k) that was contributed from my paycheck, without earnings?
(I don't have any money in a 401(k) yet, I'm looking to start contributing to a roth 401(k))