Did I Bless or Not?
A practical guide to handling uncertainty about blessings after eating

Our Sages established a great principle in Tractate Berachot: "Whoever makes a blessing that is not required (meaning, recites a blessing they are not obligated to say) transgresses the prohibition of 'Do not take [Hashem's name in vain]'." Our early Sages disagreed about the interpretation of this Talmudic statement. According to Tosafot in Tractate Rosh Hashanah (33b) and other early authorities, the prohibition against an unnecessary blessing is only rabbinical, and when the Talmud states that one who makes an unnecessary blessing transgresses 'Do not take,' it does not mean there is an actual Torah prohibition, but rather it is a rabbinical prohibition that the Sages connected to the verse "Do not take the name of Hashem your God in vain." The reason this is not considered taking Hashem's name in vain is because there is still praise to Hashem in reciting the blessing formula, and it is permitted to praise Hashem using His name, as we do in Shabbat songs when we mention Hashem's name.
However, in contrast to those authorities who believe this is only a rabbinical prohibition, the Rambam and other early authorities hold that the prohibition of an unnecessary blessing is a complete Torah prohibition, as anyone who mentions Hashem's name in a blessing format when not obligated to do so transgresses the prohibition of "Do not take the name of your God in vain." This is also the ruling of Maran the Shulchan Aruch, whose rulings we have accepted, that anyone who makes an unnecessary blessing transgresses the severe prohibition of taking Hashem's name in vain.The consensus among authorities is that in any case where we are uncertain whether to recite a blessing or not, the rule is "when in doubt about blessings, be lenient," and one should not bless due to uncertainty. One who blesses because of uncertainty commits a transgression, as they are entering into a possible situation of taking Hashem's name in vain, since they may have already blessed over what they are eating.
Therefore, Maran the Shulchan Aruch ruled (in section 209): "For all blessings, if one is uncertain whether they blessed or not, they should not bless either before or after, except for Birkat Hamazon (Grace after Meals), because it is a Torah obligation." To explain, if a person is uncertain whether they recited the blessing of "shehakol nihyeh bidvaro" over water before them, then the law is that they should not bless, and they may legally drink the water before them, since in cases of rabbinical doubt we are lenient, and the basic requirement of blessings is rabbinical (as the Sages established the laws of blessings for us, as explained in Berachot 15a). However, one is not permitted to be stringent with themselves and recite the blessing, as this would place them in a situation of possibly transgressing the Torah prohibition of taking Hashem's name in vain.
However, all this applies specifically to blessings that are only rabbinically required, but for Birkat Hamazon, which is required by Torah law, if one is uncertain whether they recited Birkat Hamazon or not, they must recite it again because of the doubt, since in matters of Torah obligation we are stringent in cases of doubt. And since one is obligated to bless because of the doubt, there is no prohibition of taking Hashem's name in vain.
The Torah obligation to recite Birkat Hamazon applies only when one has eaten and been satisfied by what they ate, but if one is not satisfied, the obligation to recite Birkat Hamazon is only rabbinical. Therefore, Rabbi Ovadia Yosef wrote that if one is uncertain whether they recited Birkat Hamazon or not, and they are not satisfied from what they ate, they should not recite it again because of the doubt, since the rule is "when in doubt about blessings, be lenient" as we explained.
Rulings of Rabbi Ovadia Yosef courtesy of "Daily Halacha" website