The colorful patches that grow in your container of mud are actually clusters of diverse species of bacteria that live naturally in the soil. Each different color represents a group of microbial species. Allowed to grow undisturbed, these bacteria form colonies large enough to see by eye.
Another name for your container of mud is a Winogradsky column, named for the scientist that came up with this way of growing and studying soil microorganisms. A Winogradsky column captures the processes that are continually happening in soil and mud in nature, a self-contained, dynamic ecosystem in which energy flows and matter cycles between different metabolically diverse organisms.
The green bacteria in your culture make their food like plants—they get their energy from sunlight by photosynthesis, and they get their matter (that is, carbon) from the air in the form of carbon dioxide. If your column is in a sunny window, you might have encouraged the growth of lots of these photosynthesizing species, and the side of the column that got less sun likely had fewer.
Other bacteria in your column are more similar to animals and fungi—they get their energy and matter by metabolizing carbon compounds made by other organisms (like plants, animals, fungi, or other microbes). This is similar to the way that you get energy and matter by digesting and breaking down the molecules in the food you eat. If you added shredded paper to your column, which is made largely of cellulose, a carbon compound made by plants, you likely encouraged the growth of some of these species, which tend to appear grey.
The egg or nails you might have added to your column represent another type of energy source that can only be used by certain bacterial species. These organisms get their energy through reactions they conduct with sulfur or iron, minerals that are present in the egg and nails, respectively. Iron-oxidizing species can often be identified by the reddish brown color of their colonies—you may have noticed that iron rusts to a similar color.
Each of these different metabolic reactions produces different waste byproducts. And each byproduct may in turn be used by another organism to survive. For example, photosynthetic cyanobacteria produce oxygen gas as a byproduct of photosynthesis. This oxygen gas is crucial for the survival of aerobic bacteria—as well as for animals like us. In fact, we have photosynthetic cyanobacteria to thank for creating the relatively oxygen-rich atmosphere of our planet several billion years ago, without which we humans could never have evolved.
Although your column might start as a uniform mass of mud, over time it develops gradients and microenvironments with different resources, such as oxygen and light. Oxygen is rich at the top of the column, but is nearly absent towards the bottom of the column, where anaerobic (non-oxygen-using or producing) species are usually found. The side of the column facing the window or other light source will tend to have more photosynthetic species than the side of the column receiving less light, which will be richer in heterotrophs, or non-light-using species. Each species occupies a particular niche or area of the column, depending on their energy and matter needs. The waste products of each species create new niches for other species to grow in.
In this way, matter recycles within and energy flows through the ecosystem of the column, and with continual inputs of light energy, these organisms can continue using their diverse metabolic processes to live, change, and grow for many years.