@Pa**
, careful with broad brush answers. :O
Most immigration offices will let you get an extension when you have 30 days or less left on your entry stamp.
Bangkok and Chiang Mai will do it at 45 days or less BUT Jomtien and some other offices will only do it when you have 15 days or less.
Check with your immigration office to see what rule they have and follow