Suppose I have about 60k in my Roth 401(k) account. (50k on contributions + 10k earned through trading stocks using the 50k over time)

I am a first time buyer and am planning to withdraw funds.. so I can withdraw only 10k tax free? Or can I first withdraw 50k as contributions and later withdraw the remaining 10k as its tax free for first time home buyer? ...how does it work?