Overview: Some Talmudic and Midrashic legends are so wild that they are rightfully disregarded as factual by the rational thinker. Were the rabbis so naïve to believe these stories and legends actually happened or were they perhaps attempting to fool us into believing them?
The overwhelming majority of Talmud consists of laws that fall under the Halacha category. But another quite popular topic in the Talmud is Aggadah and Midrash. Some teachings in Aggadah can take us by surprise; they are wild, they are inconceivable, and they are unrealistic.
The Midrash states that Sisra, who waged war against Israel,[i] came upon the Jews with four billion troops.[ii] Of course, in a time where the universal population barely reached 100,000,000, it would be impossible for this to have happened. The Midrash states that Og the Giant lifted a huge mountain above his shoulders to throw it upon the Jews.[iii] Another Midrash says that only one out of 500 Jews left Egypt while the remainder died during the plague of darkness.[iv] Being that around 2 million Israelites are estimated to have left Egypt, that would sum-up the Hebrew’s population in Egypt at 1 billion. Similar wild tales are recorded in chapter Hamocher es Hasefinah in tractate Bava Basra. Ought we really to believe these rabbis?
It is unanimously accepted amongst the rabbis of new and old that many Aggadic statements are not to be perceived as literal but are homiletical ideas.[v] The tales have a hidden message and concealed wisdom enclothed in metaphoric terms.
An example to help demonstrate the point: The Midrash says that “one woman in Egypt gave birth to 600,000 in one deliverance.”[vi] The literal understanding of this is of course logically impossible and scripturally impossible. The real meaning behind this teaching is that Yocheved gave birth to Moses who, being the leader of the Jews, is considered to be equivalent or compared to the Jewish Nation—thus 600,000.
Another example: “all of the Prophets prophesied [good things] only regarding one who marries his daughter off to a Torah scholar.” Of course, the literal understanding of this would be ridiculous. Rather the real explanation behind this is quite noticeable. It is encouraging respect for the Torah scholars, something which was lacking relatively in those times.
Similarly, there are many Aggadic statements that are intentionally exaggerated numbers or concepts. It is just to bring out the extreme point of whatever teaching it may be. Not only does rabbinic literature do so, but even Scripture itslef does so on rare occasions. [See Deuteronomy 1:28 “cities high, structures reaching the sky” and I Kings 1:40 “the land split from their loud voices.”][vii] 
Some statements are not intended for their literal understanding, but are simply to undermine a negative idea or negate an evil act. For example, the rabbis in the Talmud said that those who live outside the Land of Israel are considered as idol-worshipers.[viii] Similarly, the Talmud relates, that a sin of King David was the cause for Israel’s future sinning and exile etc.[ix] Of course, the intention in the first case was to support settlement in the Holy Land. In the second case, the intention was to magnify the transgression of King David and discourage others from doing the same.
Why did the sages write these concepts in an encrypted fashion and wrapped in metaphoric clothing?
There are a few possible explanations for this:
(1) Many of the deeper meanings are profound concepts in Kabbalah (e.g. maaseh merkava and maaseh bereshis). These concepts were traditionally confined to a small amount of people in each generation, the brightest minds and intellectuals. Others were discouraged from learning these concepts lest they misunderstand or misinterpret these profound concepts explaining the characteristics of G-d and the way He created the universe.[x]
Many examples of this category can found in Chagigah 12a-13b where the spiritual worlds are described in physical and bizarre terms.
Many Kabbalistic works were written in commentary of Aggadah throughout the Talmud. These Kabbalistic writings were open about the interpretations (unlike the Talmud) because their works in the first place are only intended for and are only read by great minds who may learn the secrets of Kabbalah. In addition, they were more open than the Talmud because their works were written in a time when the secrets of Kabbalah are believed to be more open to the public (a topic beyond our discussion at hand).
(2) Many Aggadic teachings and interpretations of the biblical narratives are intending to subconsciously send over a moral lesson and ethical teaching to those studying the teaching.
For example, the Midrash says[xi] that Pharaoh’s daughter’s hand miraculously stretched out several cubits in order to reach the basket of Moses (described in Exodus 2:5). However, this outright contradicts the literal understanding of the verse which says that she sent her slave-girl to fetch the basket.[xii] Thus, this Aggadic teaching clearly isn’t to be taken literally. It can be suggested that the inner intent of this Aggadic teaching is to emphasize the divine hand that was at play in this story. The daughter of Pharaoh had no reason to take the Hebrew child from the Nile against her father’s will. It was thus the influence from G-d that made her take the baby and raise it as her own. This is brought out in the description that her hand stretched out several cubits to reach the basket.
It can be argued that the moral lessons were taught in a subconscious way (i.e. wrapped in a metaphor) because the power of subconscious persuasion is frequently much greater than the moral lesson being taught directly.
(3) Similar to the non-literal interpretations (i.e. hints or asmachata) discussed earlier, the Aggadic teachings were wrapped in wild biblical interpretations so that the student would bump into these concepts every time he learned the Torah. Back in the days when writing the Oral Law was prohibited and even afterwards when it was inaccessible, students were limited to the study of the Written Torah. Thus a point was made to attach as many ideas possible to the Written Torah.
[Additionally, a point was made to biblicalize the moral lessons being taught in the Aggadic teaching. They were thus enclothed as an interpretation to a biblical narrative. This isn’t trickery because these moral lessons are essentially of biblical origin and its understanding of G-d.]
(4) The Talmud and Midrash were originally intended for an audience of brilliant intellectuals and rabbis. This coincided with the general education standards of its times, which was confined to the literate intellectuals. Over time, however, the Talmud became the basis of Jewish study which eventually became widespread among all classes in the populace. Because it was originally intended for the brightest of minds, is was written in a way that they easily understood the deeper intentions. When a metaphor was written, these intellectuals easily understood the deeper meaning behind it and thus there was no problem in writing it in what seems to us as an encrypted fashion.
Now, due to the obvious negative nature of these allegoric, symbolic, and metaphoric statements in the Talmud, many sages in the times of the Mishnah and Talmud itself spoke negatively on creating or learning Aggadah and Midrash.[xiii] The author of the Talmud, though, was seemingly tolerant with such ideas and wrote them every here and there in the Talmud.
Where is Aggadah from?
Midrash and Aggadah includes many philosophical concepts, theological ideas, moral lessons, and random facts. Getting down to the core of what was actually intended (i.e. taking off the metaphorical layer, in many Aggadic statements, and seeing the actual depths of the idea)—we are left with a “fact” of some sort. But the question now becomes where the sages got their facts from.
Some facts are traditions from Sinai. The rest are mostly logical deductions or are facts already mentioned in Scriptures that are only being stressed on.
It also should be noted that very frequently an Aggadic teaching, including commentary to the Torah,[xiv] isn’t a unanimous opinion but that of an individual. This is despite the fact that there’s no name that the teaching is attributed to. This in contrast to Halacha which always mentions if the Halacha is a personal opinion or a bipartisan decision. (By Aggadah, however, there was no need to be so precise and clear because there are no practical ramifications from them). This is not my personal opinion but that of the earliest post-Talmudic rabbinic sages.[xv]
Is Aggadah absolute fact?
The answer to this might come as a shock to some, but it must be noted that the answer to this question is supported both logical means and by our great rabbis.[xvi] And this answer is categorically no! Aggadah is not absolute fact. Yet, it is the probable, for if it wasn’t the probable—our sages wouldn’t teach it to us (unless it is merely an individual’s opinion, something we have no way of knowing).
As stated earlier, most of Aggadah are ideas that were derived from either logical conclusions or Scriptural analysis. Many logical conclusions, and definitely Scripture analysis have alternatives either just as valid or at least a possibility. Hence, it becomes almost impossible to establish an absolute fact given the above circumstances. It is because of this reason that the famous rule says we cannot apply Aggadah to any Halachic practical situations (i.e. in cases where it interferes with known Halachos that state otherwise).
Additionally, it must be noted that not all Midrashim in first place are reliable sources of information. Mainstream Midrash (e.g. Mechilta, Sifri, Bereishis Rabba etc.) were, as tradition claims, authored by Tannaim (revered sages of the post-Second-Temple era) and are therefore reliable. However, there are a few Midrashim that have unreliable or uncertain sources from the medieval period (e.g. Sefer Hayashar).
But why is this different than Halacha which is absolute?
Halacha isn’t telling us facts; Aggadah is. A fact cannot be determined based on a logic which has alternatives but can only be conclusive with either scientific analysis or absolute logical reasoning and conclusive proof. Whereas Halacha, on the other hand, is indeed not a “fact” but rather an instruction. This instruction doesn’t tell us of any specific reality but simply tells us what to do.
After understanding this, we can now appreciate a Tosfos Yom Tov commentary on Mishnah Nazir 5:5 which says that we have the permission to interpret Scripture and Mishnah freely, even if it interferes with Aggadah—as long as it doesn’t interfere with Halacha. Understandably, one must be sensitive with such a tool and one must understand the great brilliance of the sages and should hesitate to dispute an Aggadic teaching.
It is for this reason that Ramban argues with Aggadah multiple times throughout his commentary on the Torah. Similarly does Radak (and Rabbeinu Avraham ben Shlomeh) on Joshua 5:14 where he argues on an Aggadic teaching (at least on the literal understanding of the Aggadah). Also see Rashba on Megillah 15a for the same point.
This same concept applies to commentary to biblical verses as well (which also falls under the category of Aggadah) which at many times may be the personal opinion of singular sages who base their interpretations or commentary on vague premises.[xvii]
 Midrash and Aggadah include a wide range of topics including interpretations and exegesis of verses, stories and tales, moral and ethical lessons, and sort of any teaching outside what is related to Halacha. Although they essentially mean two separate things, Midrash and Aggadah are usually intertwined.
 There may even be, at times, an argument regarding the exact exaggerated number—despite that there’s no significance to the number. Why then do they argue? Perhaps they received this teaching in tradition from a previous generation (being that most statements in the Talmud are oral traditions that came from an earlier generation) and are therefore arguing on the exact wording of the way it was told over—even though the number was exaggerated—because there was an emphasis on the exact wording of the passed down traditions. This precision in the exact wordings of previous generations is found all throughout the Talmud. A classical example is when the Talmud says another version (ikka d’amrei) of an earlier generation’s teaching—a version which almost parallels the first and bears no practical difference Halachically. See Gittin 57a where there is an argument whether 4 billion Jews were killed in Jerusalem or “only” 40 million. They are both clearly exaggerated numbers yet assumedly they argue on a previous generation’s statement they received in tradition which consisted of some sort of “4” and the number of proceeding digits came into question.
[The number 4 seems to be a frequent number used when citing exaggerations. For instance, see Gittin 58a regarding the deaths at Beitar of which the numbers described are each multiplied by 400 (see there). It would be ridiculous to assume that all those numbers of 400 mentioned regarding Beitar all happened to be the same. It is rather clear that the numbers, specifically 400, are used for exaggerations. See also Pesachim 94a.]
 This can be seen from the fact that the Talmudic commentaries were only developed some 500 years after the writing of the Talmud, when the general populace needed a way to understand the book that was originally intended for the brightest of minds.
 Aggadah is similar to modern-day vertelach (homiletics) said by rabbis at synagogues, which are of course only theories and not absolute. The only difference is that they were said by some supremely intelligent individuals of the past.
 See also Meiri Magen Avos 1, Shiltei Giborim Avodah Zara 6a, Ramban Yevamos 61b, 71b, Ritva Shabbos 75b, Rabeinu Chananel in Otzar Geonim responsa 50.
[i] Judges Ch. 4.
[ii] Midrash Yalkut on Shoftim, chapter 43.
[iii] Talmud Berachot 54b.
[iv] Mekhilta deRabbi Yishmael, Beshalach, Masekhta deVayehi Beshalach, petichta, s.v. vayasev Elokim
[v] See Ritva on Bava Basra on chapter Hamocher es Hasefinah who explains that most of those stories were dreams with homiletical lessons in them. See as well Rambam in his introduction to the Mishnayos that they are not literal but rather lessons for life. Also see the introduction of Moshe Chaim Lutzotu (Ramchal) to Ein Yaakov who elaborates on this.
[vi] Song of Songs Rabbah 1:15, section 3
[vii] Chullin 90b.
[viii] Kesubos 110b.
[ix] Talmuud Shabbos 56b.
[x] Chagigah 11b.
[xi] Shemos Rabbah 1:23.
[xii] Cf Rashi on the verse.
[xiii]Here are some references, some of which are not detailed addresses. Jerusalem Talmud Shabbos 16, Jerusalem Talmud Maasros, Maseches Sofrim 1 and 7, chapter Ein Dorshin.
[xiv] Shmuel Hanagid in his introduction to Talmud in Berachos.
[xv] Rav Hai Gaon quoted in Otzar Geonim on tractate Berachos pirushim 67. Also see Rambam in his letter to the community of Marseille which debunks the idea of astrological effects on human behavior—an idea expressed multiple times in the Talmud in Aggadic context. Rambam therefore suggests quite vividly that the statements in the Talmud regarding this is none other than a personal opinion of which the vast bulk majority of Sages would have argued on him.
[xvi] See Encyclopedia Talmudis on “Aggadah” where it quotes this concept and brings many early sources for it, including the Geonim (post-Talmudic Babylonian Jewry Rabbis) like Rav Hai Gaon and Rav Sh’reera Gaon. See Otzaros Hageonim Chagigah chapter 67 Rav Sherirah Gaon there chapter 68; Rav Hai Gaon Eshkol second book page 47 (Hilchos Sefer Torah folio 59b-60a). See as well Talmud Yerushalmi Peah second chapter Halacha 4, Mavo LaTalmud of Rabbi Shimon Hanaggid, Rav Sadyah and Rav Hai in Miluim to Otzaros Hageonim pahe 65, Pesichah (preface) to Morah Nevuchim first section, Shaalos uTeshuvos of Chacham Tzvi chapter 49.
For more sources and a discussion of the topic, see http://www.daat.ac.il/daat/kitveyet/mahanaim/yahas-2.htm and https://rationalbelief.org.il/%D7%9B%D7%92-%D7%90%D7%92%D7%93%D7%95%D7%AA-%D7%97%D7%96%D7%9C-%D7%A2%D7%9C-%D7%94%D7%9E%D7%A7%D7%A8%D7%90/
[xvii] Shmuel Hanagid in his introduction to Talmud in Berachos, responsa of Rosh 13 21, Avraham son of Rambam in his commentary to Exodus 14:11. For an even more extreme view see Siltei Gibborim on Avodah Zara 6a.