This document presents a method for automatically identifying, analyzing, and classifying defects on printed circuit boards (PCBs). The proposed algorithm uses image registration, preprocessing, segmentation, defect detection, and defect classification. It is able to detect and classify 14 different types of defects. The algorithm is robust to variations in rotation, scale, and translation between the test and template images. It takes only 2.528 seconds to inspect and analyze a PCB image. Experimental results demonstrate the suitability of the proposed algorithm for automatic visual inspection of PCBs.