Gnats hang out in clouds because safety in numbers is a good self-defense tactic and works on almost anything.
Predators often get confused when they are surrounded by many of them, and the animals that the gnats swarm are less likely to fight back if dozens are biting them at once.
Another reason is the same reason teens tend to hang out together. The world is a big place when you’re a tiny fly, and if you’re grouped together in a small clump, you’re more likely to be able to find a willing partner when it’s time to couple up.
Gnat and teen courtship behaviors are similar in other ways; for example, male gnats will show off their desirability for mating by hot dogging and showboating, zooming quickly up to the top of the swarm and back down again.
The various species of gnats include biting midges, punkies, and no-see-ums, many of which can bite us and leave a painful sting.