The Rambam in the second chapter, and the Tur and the Shulchan Aruch wrote: If one is in doubt whether he recited Shema—he returns and recites, and blesses before it and after it. But if he knows that he recited it but is in doubt whether he blessed before it and after it—he does not return and bless. Thus far their words. The explanation of the matters: Since the recitation of Shema is from the Torah, therefore in a case of doubt—he returns and recites according to the law that a doubt regarding a Torah matter is resolved stringently. And therefore, even according to those who hold that from the Torah his obligation is only for the first verse or the first parasha, as I wrote at the beginning of siman 58, and certainly regarding the blessings which are entirely from the Rabbis, nevertheless since he becomes obligated in the essence of his obligation—he becomes obligated in everything, for such was the enactment (Rashba in a responsum, siman 320). Furthermore: that anything whose obligation is from the Torah, in a case of doubt—one must bless, such as the second festival day of the Diaspora. And even though regarding several doubts of the Torah we do not bless, such as a doubtful milah for an androgynos, and in the sounding of the shofar, and similar cases—this is because there the doubt is in the essence of their obligation. But here the obligation is clear, but the doubt is perhaps he already fulfilled it, and therefore since out of doubt—he returns and recites, he recites it all with its blessings. But when the doubt is only regarding the blessings—he does not bless, for a doubt regarding a Rabbinic matter is resolved leniently, and also there is some concern of a blessing in vain in this. But when the doubt is also regarding the recitation of Shema—there is no concern here of a blessing in vain, for according to the law it is so, as I have written.
כתבו הרמב"ם בפרק שני והטור והשולחן ערוך: ספק אם קרא קריאת שמע – חוזר וקורא, ומברך לפניה ולאחריה. אבל אם יודע שקראה אלא שמסופק אם בירך לפניה ולאחריה – אינו חוזר ומברך. עד כאן לשונם. ביאור הדברים: דקריאת שמע דאורייתא, ולכן בספק – חוזר וקורא כדין ספיקא דאורייתא לחומרא. ולכן אף להסוברים דמן התורה אין חיובו אלא בפסוק ראשון או בפרשה ראשונה, כמו שכתבתי בריש סימן נ"ח, וכל שכן בברכות שהם לגמרי מדרבנן, מכל מקום כיון שמתחייב בעיקר חיובו – מתחייב בכל, שכן היתה התקנה (רשב"א בתשובה סימן ש"כ). ועוד: דכל שחיובו מן התורה בספק – צריך לברך, כמו יום טוב שני של גליות. ואף על גב דבכמה ספיקות של תורה אין מברכין, כמו ספק מילה באנדרוגינוס, ובתקיעת שופר, וכיוצא באלו – זהו מטעם דשם יש ספק בעיקר חיובן. אבל הכא החיוב ברור אלא שהספק שמא כבר קיים, ולכן כיון דמספק – חוזר וקורא קוראה כולה עם ברכותיה. אבל כשהספק הוא רק בהברכות – אינו מברך, דספיקא דרבנן לקולא, וגם קצת חשש ברכה לבטלה יש בזה. אבל כשהספק הוא גם בקריאת שמע – אין כאן חשש ברכה לבטלה, דמדינא כן הוא כמו שכתבתי.