I found many related questions on this site but I am still not sure about the rules. How can I decide if I need a visa to transit?
It's sometimes difficult to find the right information but everything is somewhere on the EU website. Wikipedia has a good summary as well. Some embassies or government websites from the various Schengen countries also provide useful summaries. Legally, the main source for all this is the Schengen visa code.
Here is a step-by-step guide through the rules to decide if you need a visa:
1. Can you enter the Schengen area?
If you can enter the Schengen area, you can also transit there. You can enter the Schengen area if you are an EU citizen, hold a Schengen visa, a long-stay visa or residence permit from one of the Schengen countries or come from a country whose citizens don't need a visa to visit the Schengen area. If any of these apply, you can stop here, you don't need a visa. If none of these apply, read further.
2. Can you transfer without leaving the international area of the airport?
Many airports in Europe have an international area with transfer/check-in counters, waiting area, sometimes lounges, restaurants, shops or even a museum before the border checkpoint where the police check the passports of passengers entering the Schengen area. Gates for non-Schengen destinations can be accessed from this area, whereas domestic and Schengen-bound flights depart from other parts of the airport.
Whether you can transit without leaving this area will depend on your specific connection (airport/terminal, airline, time). For example, some German airports close at night, so that it's not possible to remain in the international area for an overnight transfer. Luggage belts are typically after the passport check so if your luggage cannot be checked through to a destination outside of the Schengen area, you will also have a problem.
Finally, as passengers' passports don't have to be checked on flights within the Schengen area, if you have two stopovers in the Schengen area (for example Mumbai-Vienna-Frankfurt-Chicago or Nairobi-Zurich-Frankfurt-Chișinău), you will have to leave the international area and go through the border checkpoint to catch your intra-Schengen flight. Same thing if you need to change airports.
If you have to leave the international area to make your transfer, you cannot transit without a visa and you need a full Schengen visa (and not merely an “airport transit visa”). If you can stay in the international area (“transit airside”), read further.
3. Do citizens of your country require a visa to transit airside?
If you have come so far, it means you come from a country whose citizens require a visa to enter the Schengen area. But there is still a distinction between two categories of countries among them. While most people can transit airside without a visa, citizens of a smaller list of countries need an “airport transit visa” even if they don't want to go through the border checkpoint and enter the Schengen area.
Where things get complicated is that the list of countries whose citizens need an airport transit visa is slightly different from one Schengen country to the other. There is a list for the whole Schengen area (list in Wikipedia, dark red/burgundy on the map from the EU) but individual Schengen member states can also add countries to the list. They have to inform the Commission, which keeps a list of all these requirements (current list as PDF, see also the same Wikipedia article).
If your country is not on either of these lists, stop here, you don't need a visa. On the other hand, if your country is on one of the lists (the general Europe-wide list or the one from the country where you are going to transit), you might need an “airport transit visa” but read further as there are some exceptions.
4. Are there other rules that could allow you to transit without a visa?
If your transfer requires an airport transit visa, there might still be a way to transit without a visa as the Schengen Visa code provides for some exceptions for people who hold other visas or residence permit. Note that those exceptions only apply to the airport transit visa requirement. If you need to enter the Schengen area (see question 2), these exceptions do not apply.
Specifically, you are exempted from the airport transit visa requirement if you hold a valid visa from an EU country (that's the whole EU, not only the Schengen area so also Ireland, the UK, Cyprus, Bulgaria, Romania, and Croatia), Canada, Japan or the United States of America. You are also exempted if you have a residence permit from one of these countries or from Andorra or San Marino. If that's your case, you are exempted even if you are not traveling to this country.
If you hold such a visa or residence permit, you can transit without a visa, no matter your citizenship or your destination. If you don't, you will need a visa.
Furthermore, if you just used the visa (so that it's not valid anymore but expired recently), you can still transit without a visa in the Schengen area for the return trip. This rule does not fit US visas very well because it's possible to stay legally in the US long after your visa expired. Unfortunately, if that's your case, you probably need a visa to transit in the Schengen area.
5. Can I get this visa on arrival?
No, you cannot. There are provisions for that in limited cases (mostly seamen, EU citizens' family and emergencies) but it's not regular practice in Europe. If you need a visa, the airline/ground handling personnel at your departure airport will want to see it (they can be fined if they transport you without checking) and they will deny boarding if you don't have the right to transit in the relevant airport(s).