We derive the density profile of cold dark matter halos using a self-similar accretion model . We show that if the clumpiness of the infalling matter is taken into account , then the inner density slope , \delta = d \log { \rho } / d \log { r } , is close to -1 . Compared with the density profiles predicted by different numerical simulations , we find that outside \sim 0.1 \% of the virial radius , our solutions agree best with the fitting formula proposed by Navarro et al . ( 2004 ) , d \ln { \rho } / d \ln { r } = -2 ( r / r _ { -2 } ) ^ { \alpha } , \alpha \sim 0.17 , where r _ { -2 } is a characteristic radius , inside which the density profile becomes shallower than isothermal ( \delta < -2 ) .