FASTING OVER ONE'S OWN PLIGHT
Gemara
(Beraisa): If a city is surrounded by Nochrim or a river (about to flood the city) or if a ship is about to sink (we fast); also, if an individual is pursued by Nochrim, bandits or a Ru'ach Ra'ah (evil spirit), he may afflict himself by fasting.
R. Yosi says, he may not afflict himself, lest he become dependent on others and they will not have mercy on him.
(Rav Yehudah): R. Yosi learns from "Va'Yhi ha'Adam l'Nefesh Chayah" - you must Mechaye (sustain) the Neshamah that Hash-m put in you.
10a (Beraisa): When individuals fast (over a lack of rain), they interrupt for Rosh Chodesh and days in Megilas Ta'anis.
12a (Beraisa): If an individual accepted to fast every Monday and Thursday of the year, and a day in Megilas Ta'anis occurred on Monday or Thursday:
If he vowed before Chachamim decreed, his vow overrides the decree;
If he vowed after Chachamim decreed, the decree overrides his vow.
Rishonim
Rif and Rosh (3:27): If a city is surrounded by soldiers or a river, or if a ship is about to sink, or if an individual is pursued by Nochrim, Ru'ach Ra'ah or bandits, we are Masri'a immediately on Shabbos. For all of these an individual may afflict himself. R. Yosi forbids, lest he become dependent on others and they will not have mercy on him.
Ran (DH Gemara): We learn from here that we Masri'a on Shabbos for any Choleh in mortal danger that day. The case of Ru'ach Ra'ah is taught with a ship about to sink and an individual pursued by Nochrim, which are mortal dangers that same day. Since we are Masri'a for these every day, R. Yosi forbids fasting over them, lest one become too weak to earn a living. Mar brei d'Ravna and Reish Lakish fasted so often because they did not need to earn a living.
Rif and Rosh (2b and 1:5): When individuals begin a series of fasts (over a lack of rain), they interrupt for Rosh Chodesh or days in Megilas Ta'anis. Nowadays Megilas Ta'anis is Batel, so they interrupt only for Chanukah and Purim. If a Tzibur began, they do not interrupt.
Ran (DH Gemara): Fasts of the Tzibur override days in Megilas Ta'anis, but fasts of individuals do not. This is because an individual's acceptance to fast is not so strong. We find this regarding an individual who accepted to fast every Monday and Thursday, and a day in Megilas Ta'anis occurred. His vow overrides the decree only if he vowed before Chachamim decreed, i.e. before Megilas Ta'anis was enacted.
Question: Shabbos and Yom Tov are mid'Oraisa, yet they are a 'Pesach' for a Neder. I.e. someone can annul a Neder to fast if they did not consider that it will obligate them to fast on Shabbos and Yom Tov, which is forbidden. This is because Nedarim take effect on Mitzvos (to forbid them). Why do Yomim Tovim mid'Rabanan (of Megilas Ta'anis) override Nedarim?
Answers #1,2 (Ran): Some say that 'Chachamim's decree overrides his Neder' means that he should annul his Neder (but if he does not, he must keep his Neder). Alternatively, Chachamim strengthened their decree more than mid'Oraisa Yomim Tovim.
Rejection (of both - Ran): The Yerushalmi says that if one accepted to fast and a fast fell on Shabbos or Yom Tov, he is lashed, and he does not need a Chacham to permit his vow. If a fast fell on a day of Megilas Ta'anis, some say that he fasts but does not complete the fast, and others say that he is lashed, and he does not need a Chacham to permit his vow. This shows that the decree truly overrides his vow, and the same applies to Shabbos and Yom Tov.
Answer #3 (Ran): We do not discuss a true Neder, rather, a mere acceptance to fast. This is not as stringent as a Neder. One may borrow from what he vowed to fast and repay later (12b). Acceptance of a Tzibur to fast is a proper vow.
Rambam (Hilchos Ta'aniyos 1:9): Just like the Tzibur fasts over its plight, an individual fasts over his plight. If one was sick or lost in the Midbar or imprisoned, he should fast over this and request mercy in Tefilah. He says Aneinu in each Tefilah. He should not fast on Shabbos, Mo'adim, Rosh Chodesh, Chanukah or Purim.
Magid Mishnah: The Rambam connotes that one must fast over his plight, just like the Tzibur must fast over its plight. One could have explained that the Gemara merely permits fasting. However, someone in trouble is obligated to examine his actions and repent. It is reasonable that he must fast, for this is among the ways of Teshuvah and submissiveness.
Lechem Mishneh: According to the opinion that Chachamim strengthened their decree more than mid'Oraisa Yomim Tovim, we cannot learn from the Beraisa that Megilas Ta'anis overrides an individual's vow to say that also Shabbos overrides it! However, we can learn from a Beraisa that says that Rosh Chodesh overrides it, because the Rambam holds that mid'Oraisa it is forbidden to fast on Rosh Chodesh.
Poskim
Shulchan Aruch (OC 578): Just like the Tzibur fasts over their plight, an individual fasts over his plight. If one was sick or lost in the Midbar or imprisoned, he should fast over this and request mercy in Tefilah. He says Aneinu in each Tefilah.
Kaf ha'Chayim (2,3): It is obligatory to fast. Even pregnant and nursing women should fast if possible.
Kaf ha'Chayim (5): We fast even for slight distress, whether or not it is common. Such distinctions apply only to the Tzibur.
Shulchan Aruch (ibid.): He does not fast on Shabbos, Mo'adim, Chanukah, Purim or Rosh Chodesh.
Mishnah Berurah (3): Also, he should not fast on Erev Yom Kipur.
Kaf ha'Chayim (7): This is if he accepted to fast without a Neder. If he vowed to fast every Monday and Thursday, he must permit the vow in order to eat.