Overstaying Your Visa
Many foreigners have over-stayed a visa, or residence permit, without realizing it. The Turkish government deals with overstays with either a fine and/or a ban from re-entering Turkey. These vary according to the length of the overstay. If you've overstayed for less than ten days, you will be fined when you go to the border gate to leave, but you won't receive re-entry ban. If you have overstayed for more than ten days, you'll be banned from re-entering Turkey for a specified time.
Immigration officials at the ports of entry/exit have a chart which dictates fines and re-entry bans, based on the number of days of an overstay. The fine is paid at the immigration desk at the port when you leave Turkey.
If you don't pay the fine, or if you have overstayed for more than ten days, you will receive a ban with a duration depending on how long you over-stayed. The shortest ban is 90 days. The longest is five years, with a maximum of 10 years in cases where the foreigner is determined to be a threat to public order or safety.
Dealing with Border Control Officials
Always be polite and respectful to border control officials, especially when you are leaving after an overstay. There have been many cases where the border control official involved has assessed a significantly lower fine, and not banned the traveler at all--even after an overstay for several months.
Overstaying your Residence Permit
The rules above also apply for overstays of a residence permit.
If You Are Still Living in Turkey
Unless your overstay is a very long one (especially if it's six months or more), you may be able to go to the Göç İdaresi Genel Müdürlüğü (Directorate General of Migration Management, or DGMM), pay the fine, and extend your residence permit.
If you haven't overstayed for more than six months, and are told that you need to leave the country and serve a re-entry ban, contact your country's embassy or consulate. There may be a a consular official there who can call someone at the foreigners' bureau and smooth things over, and perhaps get you a lower fine as well. There is no guarantee that it will work, but it has worked in the past for some foreigners.
Important! If you have overstayed your visa or residence permit and need to catch a flight at the airport, go early and go through passport control well before your flight. It could take an hour for the immigration officials to calculate your fine or ban, and for you to make payment for it. Then, if you miss your flight, you will have to book and pay for another one.
Arrest and Deportation for Long Overstays
If you are caught on the street with a significantly long overstay, you will be subject to arrest and deportation. If this is your situation, contact your country's embassy or consulate to make arrangements to turn yourself in, and make arrangements for leaving Turkey. By self-reporting with consular assistance, you can avoid being arrested, jailed, and deported.
The 90-in-180-day rule: Citizens of Europe, the UK, and the US can only stay in Turkey for 90 days in any 180-day period. This article covers how it works, and how it is calculated.
Calculator of travel days remaining under a Schengen short-stay visa: You can use this calculator by entering how many days you have been in Turkey, to determine how many days remain before you overstay.