Elijah went from near Beersheba to Horeb. 1 Kings 19:3–8. Deuteronomy 1:2 says Kadesh is an 11 days’ journey distance away from Horeb. Beersheba was near Kadesh, both near the south extreme of the promised land. So, why would Elijah take 40 days and 40 nights to cover that distance?
Beer-Sheba (or Be’er-Sheva, in Hebrew) may be “near” Kadesh by the standards of someone living in the US or Canada today, with modern vehicles, but not for an Israelite in the 9th B.C.—especially a northern Israelite, like Elijah, who was accustomed to the greener and more hospitable climate of northern Israel, rather than the desert wilderness of the Negev and Sinai.
More to the point, Horeb is commonly thought to be synonymous with Mt. Sinai, and although we are uncertain where that is, if it is indeed(Arabic, ‘Mt. Moses’) in southern Sinai, we’re talking of a distance of 420km, through terrain that is not only desert, but highly mountainous, most of the way. Although on paper that means only 10km a day or so, I can tell you from personal experience that even with modern hiking gear and provisions, even a quarter of that distance in that terrain is exhausting—in sandals, and with nothing more than “a cake baken on the coals, and a cruse of water” to sustain him (I Kings 19:6) for the whole journey, it’s fairly miraculous.
Besides that, the number 40 has a mystical significance in the Hebrew Bible, which is why it crops up repeatedly at crucial points in history: Noah’s Flood lasted forty days and nights; Moses spent forty days and night on Mt. Sinai when he received the Ten Commandments; and of course the Israelites spent forty years in the desert before being allowed into the Promised Land (to mention just three examples).
Going out into the desert by oneself also has mystical significance: it is an opportunity to reflect and commune with God, but also a perilous journey which only a select few survived, by divine grace (e.g., Moses, Hagar, and Elijah). Hence, the story of Elijah’s journey into the desert for forty days and nights was meant to enhance his aura as a messenger of God.
(See this and other answers to this question at Quora.com)