Here's a quick explanation of the breakdown of ammonia.
Aerobic (breathes oxygen) bacteria from the air (or from introduced sand, rock, etc.) consumes ammonia, reproduces, produces nitrites...
Aerobic bacteria consumes nitrites, reproduces, produces nitrates.
Now.. here's where the process gets a little more tricky:
Anearobic (oxygenless) bacteria consumes nitrates, reproduces, produces N gas and oxygen (i believe.. chemistry not my favorite subject).
Anearobic bacteria is found deep in the heart of live rock. Most aquariums, however, do not have enough anearobic bacteria to keep up with the demand for it; Therefore you get an eventual buildup of nitrate and must remove it through water changes.
There are other ways to harbor anearobic bacteria, though. The way that I use and am familiar with is by using a deep sand bed. The bottom couple of inches of a deep sand bed are poor in oxygen and allow for the growth of anearobic bacteria.
Hope that helps!