In this paper, we present an automated method for selecting optimal overlay sampling plans based on a systematic evaluation of the spatial variation components of overlay errors, overlay prediction errors, sampling confidence, and yield loss due to inadequate sampling. Generalized nested ANOVA and clustering analysis are used to quantify the major components of overlay variations in terms of stepper-related systematic variances, systematic variances of residuals, and random variances at the wafer, field and site levels. Analysis programs have been developed to automatically evaluate various sampling plans with different number of fields and layouts, and identify the optimum plan for effective excursion detection and stepper/scanner control. For each sample plan, the overlay prediction error relative to full wafer sample is calculated, and its sampling confidence is estimated using robust tests. The relative yield loss risk due to inadequate sampling is quantified, and compared with the cost of sampling in determining a cost-optimal sampling plan. The methodology is applied to overlay data of CMP processed wafers. The different spatial variation characteristics of oxide and metal CMP processes are compared and proper sampling strategies are recommended. The robustness of the recommended sample plans was validated over time. The sample plan optimization program successfully detected process change while maintaining accurate and robust stepper/scanner control.