No number in the Hebrew Bible is used more consistently than forty, and the consistency is the interesting part: it almost always marks a period of trial, testing or preparation that ends in a changed situation.
The rain falls forty days and forty nights in the flood at Genesis 7:12. Moses is on Sinai forty days without eating at Exodus 24:18 and again at 34:28. The spies scout Canaan for forty days at Numbers 13:25, and the forty days become forty years of wandering, a year for each day, at Numbers 14:34, the text making the correspondence explicit. Elijah walks forty days to Horeb at 1 Kings 19:8. Goliath challenges Israel for forty days. Nineveh is given forty days at Jonah 3:4. Saul, David and Solomon are each given forty-year reigns, and the judges deliver Israel for forty years at a stretch, which is a strong indication that forty is functioning as a conventional generation rather than as a count.
In the New Testament, Jesus fasts forty days in the wilderness at Matthew 4:2 and the parallel passages, an episode written in deliberate parallel to Moses and Elijah, and Acts 1:3 gives forty days between resurrection and ascension.
The question of whether these are historical durations or a literary convention is not really open. A number that recurs this often, in this many genres, with this much structural neatness, is doing the work of a unit, roughly, a generation, or as long as a serious ordeal lasts. Reading each instance as an exact tally misses what the text is doing with it. That does not make the passages less meaningful; it makes them legible.