To enter into Thailand you must have a passport valid for at least 6 months as from the date of entry.
Most nationalities can obtain a 30 day visa which is given
upon entry. If you are anticipating staying longer, then apply for a 60 day visa costing US$15 before leaving.
It is always best to check with the Thai Embassy in your home country before travelling.
Download the visa application form here
Once you have arrived in Thailand you can leave and re-enter the country to extend your visa for another
30 days. Popular border crossings are between Malaysia, Laos and Cambodia. All you have to do is cross the border and come back as there is no specification on the
length of time that you have to stay outside Thailand, although now your visa can only be extended this a maximum of 3 times in succession.
Alternatively, if you don't want to leave the country and come back then you can now have your visa extended for 10 or 15 days at the Immigration Office on Koh Samui for a fee of
between around 1500 Baht.
If you overstay the visa you have, then there is a 200 Baht daily fee with a 20,000 Baht limit. Not recommended when you have so many other choices.
This is not an extensive resource - for more information check the following websites:
Visa Types and Requirements