got money from roth ira

I withdrew 5000$ from my Roth IRA last year. My prior contributions are above 18K, lets say 18000.

when I do taxes will form 8606 gets attached to my return? or it is just like a worksheet for my info? if it gets attached i fill part 3 only? which line I write 5000 and which line  i write 18000?