[Source]
Ammonia, nitrites, and nitrates are all important in the issues regarding good water quality. They are produced at stages of the nitrogen cycle.
Through animal waste (fish feces and urine), decaying food, plants and animals the nitrogen passes into compounds that form ammonia. (which is a highly reactive gas that is toxic to animals)
Ammonia is then oxidized by bacteria and turns into nitrites and then nitrates. Nitrates are used as plant food and enter the nitrogen cycle once again.
In the natural world this is going on continuously, while in enclosed spaces such as tanks, the fish hobbyist must help to maintain a healthy balance by doing routine water changes, and not overfeeding.
Much of this can be done by using mechanical filtration to remove the organic matter (uneaten food, decaying plants, and fish waste).
In easy terms it means a fish eats and defecates and urinates and this turns to ammonia, the ammonia if not broke down by beneficial bacteria will cause illness and possibly death in your fish. So the fish keeper must do routine water changes, provide a good source of filtration and monitor water conditions and not overfeed. When the ammonia mixes with the nitrifying bacteria it creates nitrites which are less toxic than ammonia to the fish; however are converted further by bacteria and oxygen to nitrates, which are way less toxic.
Goldfish will tolerate 500mg/l; however, a high nitrate level will cause undue stress and raise the possibility of them being susceptible to disease.
There are test kits available to check for ammonia, nitrite, and nitrates. The effects of nitrite stress can be reduced in an emergency by adding 2 1/2- 2 3/4 teaspoons of aquarium salt to every gallon of water.
Read more about water conditions here
Photo taken from The Healthy Aquarium: Dr. Neville Carrington