Ten is completeness (ten fingers, and the decimal system of numbers); four is the earth (north, south, east and west) so forty denotes something that is (usually) a duration on earth that is complete in itself and an extension, or a repetition, to that duration would achieve no more.
In the situation of a trial (Jesus' temptation) the prolonging of the trial beyond forty days and nights would prove nothing more than had already been proved : his faithfulness to God, tested to extremity.
It need neither be extended nor repeated.
In the situation of Moses, the period was as long as it needed to be to convey to him all that God wished to reveal. Prolonging the time would be pointless. The period of time, and the supernatural preservation (neither food nor water) indicate that something was achieved, completely, on the earth, and that it need neither be extended nor repeated.
(Those who have attempted to write further - in effect, alternative - "scripture", pretending to some sort of repetition of Moses' experiences should have taken note of what the forty number indicates.)