Although I think History SE is a decent place to ask this, I think a better answer  would come from Biblical Hermeneutics SE. Educated guesses can be made here, but I think a more nuanced sense requires more familiarity with the Bible's use of the number, and I'm not referring to numerological or mystical interpretations. That said, I'll write what I can out of the familiarity I have.

For example, we can make one observation in line with the previous answers, namely that it is almost certainly not a literal but a symbolic number. There are at least three numbers that come up too often and at too useful a time to be coincidence: 7 (completeness; the root is related to "satiate"), 12 (traditional number of tribes of Israel, frequently recurrent), and 40.

But we can also make the problematizing observation that though it may stand for an indeterminate number, it's not exactly an "indeterminately large number" in the sense of "so many they are not worth counting". The Bible is well aware that 40 is too small a unit for most such purposes, and for big, vague numbers prefers rounded-off thousands, tens of thousands, or even hundreds of thousands. Hence, "gazillions" is not justified.

T.E.D.'s explanation comes closer, but seems to miss the point when citing the word [רְבָבָה][1] *revavah*. This word stems from a root meaning "to multiply, to become many", and *is* a good candidate for "indeterminate large number". Wiktionary and other dictionaries' gloss "10,000" does *not* refer to the "technical, literal value" of revavah but to precisely the figurative value "10,000" carried in early translations such as the KJV.

So does 40 simply mean "an indeterminate *small* number"? After all, it's probably around as small as you can get and still be indeterminate. (This is what I mean by a more nuanced reading.) It might. However, I think the Bible has a slightly narrower intention for it.

One important note is that it's almost always a period of time. (One rare exception is the number of *se'ahs* in a *mikvah*.)

When speaking of years, the Israelites wandered in the desert 40 years, with the explicit effect being that a whole generation died off. Moses fled Egypt at 40 years old and returned 40 years after that. Kings are often said to rule for 40 years. In extrabiblical sources, a person is allowed to study the Kabbalah at 40. And so on.

Meanwhile, when speaking of days, Noah's rain falls for 40 days and nights; the spies explored Canaan for 40 days; Goliath taunted the Israelites for 40 days; Moses thrice spent 40 days and nights on Mount Sinai. Elijah took a journey of 40 days to Mount Horeb. And so on.

I would thus offer an interpretation for "40 years" as a single generation in the sense of having lived a full life (in ancient lifespan terms!); you are not just the "adult" of your 13 years of bar or bat mitzvah, but have lived through the life that most adults manage to get to and acquired the relevant wisdom. Or else, you began and your time is over and it's now your children's time. It's a "small epoch", a building block in a history or geneaology of a nation, which is the sort of thing the Bible is deeply concerned with tracking, even symbolically.

Meanwhile, for "40 days" we can extend and miniaturize that meaning: it's a significant block of time within an average lifespan. We might say that 40 days is to a person's lifetime what 40 years is to a nation's history: a unit of time big enough to mark a change or a significant event.*

----

<sup>* *In sacred matters, the Bible does sometimes use the metaphor of a person for a nation, particularly the Israelite nation.*</sup>


  [1]: https://biblehub.com/hebrew/7233.htm