The bacteria do not know what a filter is. What they do is to colonize wherever what they need is available. We are talking about ammonia, nitrite, oxygen, inorganic carbon and for the most part. Moreover, the filter itself doesn't hold the bacteria, the media in the filter does this. The filter does a few things that encourages the bacteria to colonize inside them.
1. It is dark inside a filter. The bacteria are somewhat photo sensitive. They do not live in light, they want strong shade or darkness.
2. The bacteria create a biofilm which they use to attach to hard surfaces. The are not free swimming in the water for the most part. The media in the filter should provide lots of surfaces where the biofilm can attach.
3. The filter is a circulation device first and foremost. By passing water though it, the bacteria can get a continuous supply of whatever is in the water,
4. The filter return is normally an oxygenator. The roiling of the water surface facilitates the natural exchange of gases in and out of the water.
The bacteria love one's substrate as a place to live. In an unplanted substrate they will only live in about the top 1/2 inch (1.25 cm). However, in a planted tank, the plants often transport oxygen down to and out of their roots which are normally in anaerobic areas. They release the oxygen and that permits the colonization of the nitrifiers. Moreover, this also results in areas of denitrification above and below the newly created aerobic one. Also, the bacteria tend to live on the plants themselves. The bacteria will also colonize the parts of decor which are out of the direct light- rocks, decorations etc.
Plants perfer to use ammonia in the form of ammonium aka NH4. The bacteria prefer to use ammonia itself, aka NH3. Plants are able consume NH4 uch more rapidly than NH3. Some of the bacteria can use NH4 but they are less efficient at using this than NH3. It is possible to hable nitrogen perfectly in a tank which contains no plants and even no algae, However, no matter how many plants are in a tank, there will always be some amount of bacteria as well.
Finally, we cannot see the bacteria so we cannot know how many we have nor where they are living or in what numbers. But using what we can know and see we can make some assumptions. We can measure ammonia, nitrite and nitrate. We can also know about the needed carbonates/bicarbonates by measuring KH. Unless one has a very expensive lab, we must intuit the state of the bacteria in any tank using proxy measurements.
For example in a bare bottom tanks with little or no decor, almost all of the needed bacteria must live in the filter media. It may also colonize the interior walls of a filter or even the intake tubes. But in well planted tanks with a few inches of substrate or in tanks with substrate and decor and no plants, a lot of the bacteria will be outside of one's filter.
Finally, there are some dynamics of which one should be aware in terms of how much bacteria one has in a tank. The most important factor is the level of ammonia/nitrite in a tank. The bacteria multiply when there is more ammonia or nitrite than they can use. When this is the case they divide. Iit is also important to understand that, when discussing bacteria, the individual cells are less important than the total number of them. Every day some number of cells will die at the same time other cells will be dividing and creating new cells. In an established tank with a fairly stable ammonia load, the total number should remain fairly constant.
Next, because the nitrifying bacteria divide rather than forming spores, they must have a way to survive bad times or they would not have survived for so many millions of years on the planet. The bacteria have a unique ability to sense when the things they need are suddently absent. This includes oxygen, ammonia/nitrite. inorganic carbon etc. When they sense an essential butrient is gone, they do not die, they go into a state of dormancy. They are alive, but almost completely inactive. There is no reproduction but there is still a very slow decline of the number of cells. After about six minths the colony as a whole will have lost enough induviduals such that, when what they need returns and they go back to work, they will have lost some of the abulity to process the same amounts they could when they went dormant. They need to reproduce some to do this.
This decline is when they are at a more normal temperature. However, if they are kept refrigerated, this period can be as much a year before the colony starts to decline in terms of how much ammonia./nitrite it can handle. How much time is involved in a decline is a direct function of their condition when they went dormant. If they are healthy and well fed this will be closer to the maximum time and the less healthy/well fed they were then the shorter will be the time where they can resume at the seme level as when they went dormant.
What this means for us a fish keepers is that we can remove all the fish from a tank and as long as the bacteria is kept wet and it is not allowed to freeze or to be in temps much over 100F (about 38C) they should survive. It is also important to understand that when ammonia/nitrite levels etc. are reduced but not completely gone, the bacteria do not go dormant, the colony merely shrinks in size.
So if you want to preserve the bacteria in a tank because you intend to restock in the next few weeks or months, you have two options. Run the tank as usual and change some water now and then but do not add ammonia. One the other hand you can keep the bacterial colony alive and working by adding ammonia as you would in a fishless cycle. It is importnat to keep doing water changes to insure what they use is repleneshed and that nitrate is not allowed to build up. Bear in mind that the cycle is acidic. If one does not do water chnages tis will drop the pH in a tank. Think about old tank syndrome.
Believe it or not, established bacteria actually seem to do well, or even better, in pulsed ammonia than in steady ammonia leevels. This was discovered in waste water treatment facilities where the level iof incoming ammonia can fluctuate greatly, especially seasonally. I normally will hold the cycle in a tank with no fish/inverts by dosing about 2.5 ppm of ammonia every 2 to 3 days. I never go more than 3 however as I do not want to put the bacteria to sleep.
Incicdentally, my favorite filter is now the Hamburg Mattenfilter if I can use it in a tank. This is basicallly a massive amount of poreosity controlled rigid foam. If I cannot use one of these my first fallback is to use the same sort of foam in a traditional sponge filter setup. I normally use the 20 ppi foam but I used the 10 ppi for pre-filters and the 30 ppi in grow tanks or tanks with inverts. The higher the porosity, the faster the foam can clog.
Clogging is the enemy of bio-filtration. For any filter media to work, it must allow water to pass though all the various pathways available. There more of these that are shut from clogging, the fewer places there will be for the bacteria to thrive and function. This is why we so often see the recommendation that the time to clean ones filter media is when we see that the filter output flow is slowing..