The evolution of the body cavity (also known as a coelom, pronounced "seel-um") was crucial to allowing the development of larger and more complex animals. Animals with one — which are the vast majority — are known as coelomates, while animals without one are called acoelomates. There are also animals without a true coelom, which instead have a structure called a pseudocoel. These include nematodes, rotifers, kinorhynchans (mud dragons), nematomorphs, gastrotrichs, loriciferans (brush heads), priapulidans (penis worms), acanthocephalans (spiny-headed worms), and entoproctans (goblet worms). Most of these are microscopic.
Body cavities are always filled with fluid. The purpose of the space is to let the organs slide independently of the body wall, cushion the organs, and allow easy chemical exchange between the organs and the rest of the body. They are thought to have evolved in triploblastic bilaterians (bilaterally symmetric animals with three tissue layers) about 600 million years ago, around the dawn of known multicellular organisms in general. Animals with a body cavity evolved from basic cnidarians, which might have looked something like modern day hydra, which does not have one. One theory argues that the cavity evolved from the gastric pouches (stomachs) of early cnidarians.
At one point, it was thought that acoelomate animals were all related to each other, forming an independent clade. This is now known to be false, as most scientists agree that acoelomate triploblasts (any animals besides cnidarians or sponges) evolved from coelomate ancestors. This reduction of the coelom occurs due to an evolutionary streamlining process, and it is particularly common among parasites. Because they lack an efficient means of transferring nutrients and other chemicals between the organs and the rest of the body, acoelomate animals tend to be flat, as this makes diffusion possible. Besides just a body cavity, coelomate animals often have dedicated circulatory organs to move around nutrient and oxygen-rich bodily fluids.