The Chachamim instituted three daily prayers: Shacharit, corresponding to the morning Tamid offering; Minchah, corresponding to the Tamid of the afternoon; and Ma’ariv, corresponding to the raising of the organs and fats upon the altar. Just as when the Temple existed and every individual was permitted to bring voluntary offerings, so too, an individual is permitted to recite an additional voluntary Shemoneh Esrei. In order for his prayer to be recognized as voluntary, he must add some sort of special personal request in that prayer. We do not offer a Musaf offering voluntarily, therefore, one may not recite Musaf voluntarily. And just as we do not offer voluntary offerings on Shabbatot and festivals, so too, there are no voluntary prayers on those days (Shulchan Aruch 107:1-2). Anyone who wants to say a voluntary prayer must be certain that he is careful and capable of having kavanah in his prayer from beginning to end. If he cannot concentrate well, it is best that he does not recite a voluntary prayer at all (Shulchan Aruch 107:4). Nowadays, the accepted teaching is that we do not recite voluntary prayers because we do not have the proper kavanah.
One who is uncertain as to whether or not he recited one of the three daily prayers, as long as the time for its recital has not yet passed, he recites the prayer and makes a stipulation in his heart. He thinks, “If I already prayed, this prayer is considered a voluntary prayer, and if not, this is an obligatory prayer.” It is unnecessary to introduce any personal requests into that Amidah, since the fact that he is avoiding uncertainty is itself the innovation. Even though we do not recite voluntary prayers nowadays, we are permitted to do so in order to avoid uncertainty. If, in the middle of that Amidah, one remembers that he already prayed, he continues to recite the Amidah until the end and adds a personal request to illustrate that it is, indeed, a voluntary prayer. This is allowed because he made a stipulation in the beginning of his prayer explaining that his Amidah should be considered voluntary if, in fact, he already prayed.
If a person starts to pray on the basis that his prayer is obligatory, thinking that he did not yet pray, but suddenly remembers in the middle of his Amidah that he already did, he must stop immediately. His prayer cannot become voluntary, for just like there is no offering that is partly obligatory and partly voluntary, so too, there is no prayer that begins as obligatory and ends as voluntary (Shulchan Aruch 107:1).
One who is daydreaming in the middle of his prayer to the point where he is unsure what part of the Amidah he is reciting, for instance, a person who is pondering whether he is reciting the sixth berachah or the tenth, according to most poskim, in order to avoid uncertainty he must return to the sixth berachah and start to pray from that point on.