Basically, when you put fish into a new clean tank, their poops and uneaten food produce ammonia. Ammonia is pretty toxic and will burn and kill the fish. However if there is a reasonable supply of ammonia, bacteria will start to grow. They eat the ammonia and produce nitrite. Nitrite is also poisonous. But when there's a good supply of nitrite in the water, another kind of bacteria grows. They eat the nitrite and produce nitrate. Nitrate is only a little bit poisonous... it has to buildup for a while before your fish are harmed. Plants eat it. When the ammonia-eaters and the nitrite-eaters are established in your tank, the poops and and food just get swapped to the nitrate.
To summarize:
Ammonia-->Nitrite-->Nitrate
That's what's called biological filtration... that's the main reason your filter works... it has a sponge with lots of surface area for the bacteria to live, and then pulls the water over the sponge so they can gobble up all the badness and make nitrate. The bacteria will also live in your gravel and on the glass, so it's important not to scrub your tank out. And you'll still need to do a little water change ever week or the nitrate will build up to toxic levels.
But as you can see it takes a while for the ammonia-eaters to grow, for them to make a supply of nitrite, then for the nitrite-eaters to grow.
So when you're just setting up a tank, it has nada, and to get it properly set up you need an inital source of ammonia. You can do this with fish, a non-fish ammonia source, or bottle bacteria (maybe).
If you use fish, whatever fish you first put in is going to have to sit in ammonia-water, then nitrite-water before the tank is nice and comfortable. Some fish can withstand the toxic stages but for others its insta-death. Bettas are pretty tolerate... so are zebra danios and some others (if you go to a good fish store they should help you out).
Your other options are store bought bacteria in a bottle (my fish store says it works, but I've heard other people say it doesn't), or you can do a fishless cycle where you just put fish food or ammonia from the store in your water for a while. The bottle stuff works pretty quickly (if it works), doing it with eg fish food will probably take weeks.