The formation mechanism of linear and isopropyl cyanide (hereafter n-PrCN and i-PrCN, respectively) in the interstellar medium (ISM) has been proposed from the reaction between some previously detected small cyanides/cyanide radicals and hydrocarbons/hydrocarbon radicals. n-PrCN and i-PrCN are nitriles therefore, they can be precursors of amino acids via Strecker synthesis. The chemistry of i-PrCN is especially important since it is the first and only branched molecule in ISM, hence, it could be a precursor of branched amino acids such as leucine, isoleucine, etc. Therefore, both n-PrCN and i-PrCN have significant astrobiological importance. To study the formation of n-PrCN and i-PrCN in ISM, quantum chemical calculations have been performed using density functional theory at the MP2/6-311++G(2d,p)//M062X/6-311+G(2d,p) level. All the proposed reactions have been studied in the gas phase and the interstellar water ice. It is found that reactions of small cyanide with hydrocarbon radicals result in the formation of either large cyanide radicals or ethyl and vinyl cyanide, both of which are very important prebiotic interstellar species. They subsequently react with the radicals CH2 and CH3 to yield n-PrCN and i-PrCN. The proposed reactions are efficient in the hot cores of SgrB2 (N) (where both n-PrCN and i-PrCN were detected) due to either being barrierless or due to the presence of a permeable entrance barrier. However, the formation of n-PrCN and i-PrCN from the ethyl and vinyl cyanide always has an entrance barrier impermeable in the dark cloud; therefore, our proposed pathways are inefficient in the deep regions of molecular clouds. It is also observed that ethyl and vinyl cyanide serve as direct precursors to n-PrCN and i-PrCN and their abundance in ISM is directly related to the abundance of both isomers of propyl cyanide in ISM. In all the cases, reactions in the ice have smaller barriers compared to their gas-phase counterparts.