Aquariums in general -- and saltwater aquariums in particular -- would not be possible without the nitrogen cycle. In the nitrogen cycle, animals produce toxic ammonia which is ultimately converted into less-toxic nitrogen compounds like nitrate. However, nitrate itself is still not desirable in a saltwater tank; most saltwater organisms find it toxic.
Sources of Nitrate
Nitrate in the aquarium ultimately comes from ammonia, which is produced by a number of biological processes. All animals produce ammonia when they break down proteins, so the main source of ammonia is biological waste. Rotting food and decaying biological material like dead fish and dead invertebrates also produces ammonia. Bacteria in the aquarium will convert ammonia into less toxic nitrite, then much-less-toxic nitrate. While any detectable level of ammonia and nitrite in an aquarium is harmful, very low amounts of nitrate may not cause problems.
You don't want any detectable nitrates in your aquarium. However, in the real world, that's improbable. A measure of 5 parts per million to 40 pmm is considered a safe range -- but keep in mind that different organisms have different levels of tolerance for nitrate. In a fish-only aquarium, you can have levels on the higher end of this range, up to 40 ppm. However, corals and other invertebrates tolerate nitrate poorly. If you have a reef tank with inverts, you will want to keep the nitrate below 5 ppm for their health and safety.
When to Test
You need to periodically test for nitrates. In a new tank, you should test at least once a week. However, aquariums become more stable the longer they are up and running. Once you've finished adding your fish and invertebrates, you can cut back on testing, checking the nitrate levels about once a month. However, if something looks wrong before a month's up, you should test. For example, if your fish start acting lethargic or your corals retract their tentacles for no apparent reason, check nitrate levels as part of your troubleshooting.
You have several methods to control nitrate in your aquarium. Most involve limiting ammonia in your setup. Avoid overfeeding your fish, and do not overcrowd your tank. You should also include deep sand beds and live rock to encourage the growth of ammonia/nitrite/nitrate-eating bacteria. You can also include macroalgae -- fish geek talk for seaweed -- in your aquarium. Like higher plants, macroalgae absorb nitrogen compounds like nitrate. The time-tested way to control nitrates is through monthly water changes. Always perform 10 percent water changes every month, and perform 50 percent water changes if you detect nitrate above the safe range for your setup.