Aims. Photodissociation by UV light is an important destruction mechanism for carbon monoxide (CO) in many astrophysical environments, ranging from interstellar clouds to protoplanetary disks. The aim of this work is to gain a better understanding of the depth dependence and isotope-selective nature of this process.Methods. We present a photodissociation model based on recent spectroscopic data from the literature, which allows us to compute depth-dependent and isotope-selective photodissociation rates at higher accuracy than in previous work. The model includes self-shielding, mutual shielding and shielding by atomic and molecular hydrogen, and it is the first such model to include the rare isotopologues C 17 O and 13 C 17 O. We couple it to a simple chemical network to analyse CO abundances in diffuse and translucent clouds, photon-dominated regions, and circumstellar disks. Results. The photodissociation rate in the unattenuated interstellar radiation field is 2.6 × 10 −10 s −1 , 30% higher than currently adopted values. Increasing the excitation temperature or the Doppler width can reduce the photodissociation rates and the isotopic selectivity by as much as a factor of three for temperatures above 100 K. The model reproduces column densities observed towards diffuse clouds and PDRs, and it offers an explanation for both the enhanced and the reduced N( 12 CO)/N( 13 CO) ratios seen in diffuse clouds.