We report the detection in IRC +10216 of 63 rotational transitions of HCN, most of them with quantum numbers J = 3-2, pertaining to 28 different vibrational states with energies up to 10 700 K (nu(1) + 3 nu(2) + nu(3)). Some of the transitions were also observed for the rare isotopologue (HCN)-C-13. The observations were carried out with the IRAM 30-m telescope. The HCN lines with level energies above 5000 K arise within 1.5 stellar radius from the photosphere. Their intensities imply a vibrational temperature of T-vib similar or equal to 2400 K and a fractional HCN abundance relative to H-2, x(HCN) = 5-7 x 10(-5). These high-energy levels are mainly populated by photospheric radiation, and their vibrational temperature yields a direct measurement of the stellar photospheric temperature. The lines with energy levels between 2000 and 5000 K yield T-vib similar or equal to 1300 K and x(HCN) similar or equal to 0.8-2 x 10(-5). They are radiatively excited and arise from a shell extending between 1.5 and 5 stellar radii. Finally, the lines from the low-energy vibrational states (<2000 K) trace a larger region of the envelope (5-28 stellar radii) with T-vib = 400-600 K and x(HCN) = 4-6 x 10(-6). They are strongly affected by mid and near-infrared pumping. The line widths increase from 5 km s(-1) near the 2400 K photosphere, to 19 km s(-1) in the warm 400 K shell. This provides a unique insight into the physical conditions of the gas acceleration and dust formation region.