Context. The envelopes of asymptotic giant branch (AGB) stars are irradiated externally by ultraviolet photons; hence, the chemistry is sensitive to the photodissociation of N 2 and CO, which are major reservoirs of nitrogen and carbon, respectively. The photodissociation of N 2 has recently been quantified by laboratory and theoretical studies. Improvements have also been made for CO photodissociation. Aims. For the first time, we use accurate N 2 and CO photodissociation rates and shielding functions in a model of the circumstellar envelope of the carbon-rich AGB star, IRC +10216. Methods. We use a state-of-the-art chemical model of an AGB envelope, the latest CO and N 2 photodissociation data, and a new method for implementing molecular shielding functions in full spherical geometry with isotropic incident radiation. We compare computed column densities and radial distributions of molecules with observations. Results. The transition of N 2 → N (also, CO → C → C + ) is shifted towards the outer envelope relative to previous models. This leads to different column densities and radial distributions of N-bearing species, especially those species whose formation/destruction processes largely depend on the availability of atomic or molecular nitrogen, for example, C n N (n = 1, 3, 5), C n N − (n = 1, 3, 5), HC n N (n = 1, 3, 5, 7, 9), H 2 CN and CH 2 CN. Conclusions. The chemistry of many species is directly or indirectly affected by the photodissociation of N 2 and CO, especially in the outer shell of AGB stars where photodissociation is important. Thus, it is important to include N 2 and CO shielding in astrochemical models of AGB envelopes and other irradiated environments. In general, while differences remain between our model of IRC +10216 and the observed molecular column densities, better agreement is found between the calculated and observed radii of peak abundance.