What is one to do if he is in unsure as to which blessing in Shemoneh Esrei he is holding by?
In the event that one is unsure as to which blessing in Shemoneh Esrei he is currently up to, one enters into a difficult Halacha dilemma as to how he should continue. On the one hand, we have a rule that whenever one is in doubt if he said a blessing, he may not repeat it, as Safek Brachos Lihakel, and accordingly, we should rule that he may only continue from a blessing which he knows for certain he has not yet said. On the other hand, one is required to recite all the blessings of Shemoneh Esrei, and one who skips even one blessing in Shemoneh Esrei is not Yotzei. Thus, if we make him skip the questionable blessings that perhaps he did not say, it would render all of his other blessings in vain. Practically, the Poskim debate the proper directive in this issue, as we will now explain.
By the first three and last three blessings: If one is unsure as to which blessing in Shemoneh Esrei he is currently up to within the first three blessings or the last three blessings of Shemoneh Esrei, then he is to return to the first blessing of that set and repeat from there. Thus, if he is unsure as to whether he has said the 1st blessing of Magen Avraham, or the 2nd blessing of Michayeh Meisim, or the 3rd blessing of Hakeil Hakadosh, then he is to restart from the beginning of Shemoneh Esrei, from the first blessing of Magen Avraham. If he is unsure as to whether he has said the 17th blessing of Avoda [i.e. Ritzei], or the 18th blessing of Hoda’h, or the 19th blessing of Sim Shalom, then he is to repeat from Ritzei.
By the middle blessings: If one has for certain said the first three blessings brought above, but is unsure as to which of the middle blessings in Shemoneh Esrei he is currently up to, then some Poskim rule that he is to skip all the blessings of which he has doubt, and continue Davening only from the blessing that he knows for certain that he did not say. Majority of Poskim, however, rule that he must repeat all the blessings of which there is doubt as to whether they were said, and he thus continues Davening from the last blessing that he knows for certain that he said. [Practically, while some Poskim offer various methods of circumventing the above debate [as stated in the footnote], the final ruling follows the latter opinion, and that one may repeat all the questionable blessings. This certainly applies to Chabad Chassidim who follow the rulings of the Tzemach Tzedek, who likewise takes the latter view.]
The definition of a doubt: It is only considered a doubt if upon return to concentration on the prayer, he does not remember the words he was saying, or if he remembers the last words but is unsure as to which blessing the words he said belong to [i.e. he said Baruch Ata Hashem and then realized he does not know what blessing he is up to]. If, however, he knows what words he was saying when he returned his concentration, then he is to continue from those words even if he does not have any recollection of saying any of the words or blessings that precede those words.
If one is unsure as to which blessing in Shemoneh Esrei he is currently up to, then if the doubt occurs within the first three blessings, or the last three blessings, of Shemoneh Esrei, then he is to return to the first blessing of that set and repeat from there. If one certainly has said the first three blessings, but is unsure as to which of the middle blessings in Shemoneh Esrei he is currently up to, then he is to repeat from the last blessing that he knows for certain that he said. Nonetheless,
 See Piskeiy Teshuvos 119:5; See regarding if one is in doubt if he said Shemoneh Esrei at all, that he should repeat it as a Nedava with a Tnaiy: Admur and Michaber 107:1; Rebbe Yochanon in Brachos 21a
 See Michaber 209:3 “All blessings of which one is in doubt if he said them or not, he is not to recite them”
 See Admur 104:4; 119:4; Michaber 119:2; Rambam Tefiula 10:4; Rav Assi in Brachos 34a
 Chayeh Adam 24:21; Ben Ish Chaiy Mishpatim 10 regarding first three blessings
 The reason for this is because this doubt is considered a mistake in the blessing, and whenever a mistake is made within the first or last three blessings, we require one to repeat, as we rule regarding Mashiv Haruach [for Nussach Ashkenaz], Yaaleh Veyavo, Hamelech Hakadosh and so on.
 Chayeh Adam ibid, based on Rama 422:1 regarding Yaaleh Veyavo; Ashel Avraham Butchach 119; Tehila Ledavid 108:16; Maharam Arik in Hagahos Minchas Pitim on 119
 The reason: One cannot repeat the blessing, as Safek Brachos Lihakel. Likewise, one cannot repeat it as a Nedava, as we do not make a prayer a partial Nedava. [See Admur 107:2; Michaber 107:1; Shmuel in Brachos 21a] A proof for this can be brought from the Rama regarding one who is in doubt if he said Yaaleh Veyavo in Rosh Chodesh, that he does not repeat it and rather continues Shemoneh Esrei. [Rama 422:1; Kol Bo 11] Thus, from this we can deduce that whenever one is in doubt if he said a blessing, the Sages did not require one to repeat it, and the Shemoneh Esrei nevertheless remains valid. [Nishmas Adam on Chayeh Adam ibid] A further proof for this approach can be brought from the Poskim who rule that a skipped blessing only invalidates Shemoneh Esrei if one could have said it. If, however, one does not know all of the blessings, then he is to only say the blessing that he knows. [see Admur ibid; 104:4 in parentheses; M”A 593:2 (implication from Michaber and Braisa); Birchas Habayis 40:29; M”B 593:2] Thus, likewise here, since one is in doubt as if he said the blessing, and he cannot repeat it due to Safek, he may nevertheless continue his prayer. [Ashel Avraham ibid; Tehila Ledavid ibid]
 Tzemach Tzedek O.C. 3 letter 9 “In Shemoneh Esrei, one who is in doubt if he said a certain blessing or did not yet say it, seemingly he may rely on the above opinion and repeat the blessing.”; Implication of Yerushalmi Brachos 5:3 and Tzelach Brachos 29b; Chesed Lealafim 107:1; Ben Ish Chaiy Mishpatim 10; Pischeiy Teshuvah 119; Orchos Chaim Spinka 119:4; Sdei Chemed in Michtav Lichizkiyahu 10:6; Birchas Habayis 40:26; Eretz Tzevi 3 Siach Hasadeh Birchas Hashem 6; Kaf Hachaim 119:20; Kehilas Yaakov Brachos 13 [of Steipler]; Orchos Rabbeinu 3:107 that so ruled Chazon Ish; M”B 188:6 in Biur Halacha “Lachzor” regarding Birchas Hamazon
 The reason: As one does not fulfill his obligation of Shemoneh Esrei if he skips a blessing. [Admur 104:4; 119:4; Michaber 119:2; Rambam Tefiula 10:4; Rav Assi in Brachos 34a] and hence one is required to repeat from the last blessing that he knows for certain that he said in order not to place his remaining blessings in jeopardy of being in vain. This is not considered a blessing in vain, as some Poskim rule that one may choose to repeat a blessing in order to escape a doubt and one may rely on this ruling in such a case. [Tzemach Tzedek ibid]
 Some of the suggested methods of circumventing the dispute: 1) One is to repeat the questionable blessings in his mind. [Ashel Avraham Butchach 582:1; Minchas Yitzchak 5:2 based on Maharam Shick 42, that in a case of need, we rely on the Rambam who rules thought suffices; See also Admur 62:3] 2) Delay continuing Shemoneh Esrei until the Chazan says Chazaras Hashatz and have in mind to be Yoztei with him all the blessings until one reaches the blessing he knows for certain that he did not say. [Piskeiy Teshuvos ibid] 3) To continue until Shemoeia Tefila and repeat all the questionable blessings there without a Chasima. [Me’at Mayim 9, based on Peri Chadash and Biur Halacha 117 “Veim Lo Shal”] Practically, it is better not to rely on the above suggestions, as practically the main Halacha is that one does not fulfill his obligation in such a case, and that one is required to repeat the blessings, as rule majority of Poskim.
Repeating the questionable blessings with a Tnaiy Nedava: The Poskim rule regarding if one is in doubt if he said Shemoneh Esrei at all, that he should repeat it as a Nedava with a Tnaiy. [Admur and Michaber 107:1; Rebbe Yochanon in Brachos 21a] This would imply that there exists a simple solution to our above case, which is directed in Shulchan Aruch, that if one is in doubt regarding the blessing that he is holding, he should repeat from that blessing with a stipulation at heart, that if he did not say it, the blessing is being said out of obligation, and if he did say it, then he is repeating it as a Nedava, which is allowed. However, in truth this solution is incorrect, as the concept of a Nedava only applies by a full Shemoneh Esrei prayer, however within a single prayer, it must either be entirely a Nedava or entirely an obligation, and not a mixture of both, in which some blessings are said as a Nedava and others as an obligation. Accordingly, one does note scape in this solution the worry of a blessing in vain, accoridng to the stringent opinion. [See Nishmas Adam 24:21]
 As so rule the majority of Poskim
 See Chesed Lealafim 107:1; Yifei Laleiv 118:5; Beis Oveid 159; Kaf Hachaim 119:20; Piskeiy Teshuvos ibid footnote 34; So rule Poskim regarding Shema [See Admur 64:4; Michaber 64:3-4; Brachos 16a]