If you are a citizen of countries such as UK, USA, Canada, Australia, NZ, EU member nations, then you may qualify for a 30 day entry stamp (aka visa waiver entry). To qualify, you need to 1) document that you will depart Thailand before the 30 days are up (confirmed airline booking); 2) prove financial status (10,000 baht for one person). Thai immgration rarely checks these two, BUT they can as I have personally witnessed people being asked. Your airline will confirm item one before they let you board. To stay longer a 60 day tourist can be applied for in advance.
If you are a citizen of countries such as India, you can apply for a Visa On Arrival which gives you 15 days. Or you can apply in advance in India and receive a visa for 30 days.
Visa waivers, VOAs and tourist visas are all single entry and expire when you depart irregardless of how many days you used. Travelers qualifying for visa waiver entry can get a new stamp each time they enter, though immigration officers now have powers to deny one if they feel you are abusing the system and staying too long in country. Folks traveling on tourist visas need to arrange multiple visas to reenter.
Visa waiver entries and tourist visas can be extended once for 30 days once in Thailand, but this ability to extend does not negate the requirement to prove you are leaving before the initial 30 day permit.
All of these rules are at the discretion of the immigration official, they can shorten your permitted stay if they feel it warranted. These rules can change without notice, as Thailand been frequently adjusting its rules to encourage tourism while trying to weed out expats who are flying under the radar.