We find the number 40 in several places in the Torah. 40 days of rain during the flood; Moses was on Mount Sinai 40 days receiving the Torah; the minimum amount of water required in a mikveh - ritual bath - is 40 seah (halachic measures). The Torah prescribes 40 lashes for some serious crimes. In addition, our Sages teach that a fetus takes 40 days from conception to develop into human form.
The Maharal of Prague, Rabbi Yehuda Loewe, explains that the number 40 always means cataclysmic change and new creation. The flood eradicated all trace of the terrible spiritual state that existed previously and created a new mankind. By receiving the Torah, the Jews were born as a new nation. One who is impure immerses in the mikveh and emerges as a new person who is pure. Lashes motivate the criminal to recreate himself spiritually and return to the ways of the Torah.
Our Sages teach that the world was created through ten Divine utterances. Mystically, each of these ten utterances manifests itself on four different levels, hence a total of forty. On Shabbat, we refrain from 39 categories of forbidden labor. The Talmud refers to these 39 as "forty minus one" because each one parallels one of the forty levels of creation, except for the highest level of creation - creation of something from absolute nothingness - which has no parallel in our physical world.