Imagine you had a ping pong ball, and you filled it with cool whip. Now shrink that whole thing down to the size of a fly. Now imagine you threw that tiny little shell full of goop at the wall. Even if you threw it as hard as you could, it’s still so tiny and so tough and bouncy on the outside that it will just bounce off.
Flies have an exoskeleton that’s incredibly tough and hard in some spots, and just flexible enough to be springy and bouncy in others. Just like that ping pong ball, they have got a shell that’s good at taking a bit of a hit and bouncing off instead of just squishing like a worm (which doesn’t have that tough shell).
The fact that they’re so small helps in a couple different ways as well. For one, we think they’re flying super fast, but it’s really just because they’re tiny. If you look at a massive airplane, it might be moving at 500 miles per hour but still looks like it’s just crawling along across the sky. Houseflies look fast, but they only go about 5 miles per hour. That means a baseball pitcher can throw a fastball 20 times as fast as a housefly flies.
Not only are they actually super slow (if you don’t let the size trick you), they also weigh almost nothing. Like, it would take about 200 flies to add up to the weight of a single ping pong ball.
So your ping pong ball full of cool whip is actually super tough, reaaally slow, and unbelievably lightweight, meaning that dumb little fly was designed to fly into the window several thousand times before it finds the opening. Evolution at work.