One of the main challenges facing upcoming cosmic microwave background(CMB) experiments will be to distinguish the cosmological signal fromforeground contamination. We present a comprehensive treatment of thisproblem and study how foregrounds degrade the accuracy with which theBoomerang, MAP, and Planck experiments can measure cosmologicalparameters. Our foreground model includes not only the normalization,frequency dependence, and scale dependence for each physical component,but also variations in frequency dependence across the sky. Whenestimating how accurately cosmological parameters can be measured, weinclude the important complication that foreground model parameters (weuse about 500) must be simultaneously measured from the data as well.Our results are quite encouraging: despite all these complications,precision measurements of most cosmological parameters are degraded byless than a factor of 2 for our main foreground model and by less than afactor of 5 in our most pessimistic scenario. Parameters measured thoughlarge-angle polarization signals suffer more degradation: up to 5 in themain model and 25 in the pessimistic case. The foregrounds that arepotentially most damaging and therefore most in need of further studyare vibrating dust emission and point sources, especially those in theradio frequencies. It is well known that E and B polarization containvaluable information about reionization and gravity waves, respectively.However, the cross-correlation between polarized and unpolarizedforegrounds also deserves further study, as we find that it carries thebulk of the polarization information about most other cosmologicalparameters.