They are embedded in a slime like film called a biofilm. If a bit of slime were magnified you would see hundreds of bacteria as well as worms and diatoms. The presence of a biofilm is the reason why goldfish can be kept in small plastic pools without any obvious filtration. The surface of the pools provide ample space for the nitrifying bacteria and biological filtration. The trick is never to scrub off this film as it would destroy the nitrifying bacteria and lead to water quality problems.
Aeration is required for the fish and the bacteria.
When a tank is first set up hundreds of bacteria are associated with the gravel and tap water. As the temperature increases in the aquarium, the bacteria multiply until there may be more than 10 million per milliliter. That results in cloudy water. Eventually the bacteria clouds will disappear naturally. After the bacteria have divided several times they use up their energy reserves and they fail to multiply.