Thailand’s trains are slow but fun – they provide comfortable sleeping berths for the overnight travel from Bangkok to Surat Thani, where travellers can then catch a ferry to Koh Samui.
Seat61.com is an excellent guide to travelling by train across the world and they have a detailed rundown of catching the train from Bangkok to Surat Thani.
Joint tickets for both the train and ferry legs of the Bangkok to Koh Samui journey are available – see ThailandTrainTicket.com to look up exact departure and arrival times from Bangkok to Samui for your specific dates.
You can not bother with a joint ticket and make your own way from Surat Thani train station to Surat Thani city (the train station is about 15 km outside the city) and then buy a ferry ticket on arrival. Here’s a useful first hand account of getting from Surat Thani’s train station to Koh Samui.