The CMS silicon tracker, consisting of 1440 silicon pixel and 15148 silicon strip detector modules, has been aligned using more than three million cosmic ray charged particles, with additional information from optical surveys. The positions of the modules were determined with respect to cosmic ray trajectories to a precision of 3-4 microns RMS in the barrel and 3-14 microns RMS in the endcap in the most sensitive coordinate. The results have been validated by several methods, including the laser alignment system, and compared with predictions obtained from simulation. Correlated systematic effects have been investigated. The track parameter resolutions obtained with this alignment are close to the design performance.