Chemistry - Why do SN2 reactions of alkyl halides proceed differently with KCN and AgCN?
Solution 1:
The cyanide anion is an example of an ambident nucleophile, these are nucleophiles which, usually due to delocalisation, are able to attack an electrophile from two or more atoms. In the case of the cyanide anion reaction from carbon leads to nitriles, whilst reaction from the nitrogen leads to isocyanides.
To give the full IUPAC definition from the Gold Book:
A description applied to a chemical species whose molecular entities each possess two alternative and strongly interacting distinguishable reactive centres, to either of which a bond may be made in a reaction: the centres must be connected in such a way that reaction at either site stops or greatly retards subsequent attack at the second site. The term is most commonly applied to conjugated nucleophiles. [...]
To answer your actual question about why $\ce{KCN}$ forms nitriles, whilst $\ce{AgCN}$ forms isocyanides, March's Organic Chemistry (7th ed., p 449) gives a pretty concise answer in which we consider the extent to which the cyanide anion is associated with the counter-cation in solution.
All negatively charged nucleophiles must of course have a positive counterion. If this ion is $\ce{Ag+}$ (or some other ion that specifically helps in removing the leaving group), rather than the more usual $\ce{Na+}$ or $\ce{K+}$, then the transition state is more $\mathrm{S_N1}$ like. Therefore the use of $\ce{Ag+}$ promotes attack at the more electronegative atom. For example, alkyl halides treated with $\ce{NaCN}$ generally give mostly $\ce{RCN}$, but the use of $\ce{AgCN}$ increases the yield of isocyanides ($\ce{RNC}$).
[See footnote]
This, of course, is not a complete picture, as solvent effects greatly change the reactivity. In protic solvents (MeOH, to give a possible example) the most electronegative atoms (nitrogen in this case) will be solvated to a greater extent via H-bondng. In aprotic solvents (THF/DMF, to give possible examples) the anion isn't solvated quite so much (on either atom of the nucleophile), but the cation is somewhat more solvated, leaving the nucleophile more able to attack (via the most electronegative atom as this is the most nucleophilic in the absence of other factors).
Footnote: As an aside at this point, it's important to realise that these are not fully covalent bonds (in $\ce{AgCN}$ and $\ce{KCN}$), despite having some level of covalent character. We're somewhat bastardising the Winstein model of nucleophilic substitution in which we define $\mathrm{S_N1}$/$\mathrm{S_N2}$ based upon the separation between the cation and the anion at the point when substitution takes place, with the two mechanisms being extremes of a continuum:
Solution 2:
The different reactivities of $\ce{KCN}$ and $\ce{AgCN}$ with alkyl halide, giving nitriles and isonitriles, respectively, has often been cited as a prime example of Pearson’s hard and soft acids and bases (HSAB) theory. The reasoning was that ‘hard’ electrophiles preferentially attack the ‘hard’ nitrogen centre while ‘soft’ electrophiles prefer the ‘soft’ carbon centre. This was often further explained by a change from an $\mathrm{S_N2}$-type mechanism (with $\ce{KCN}$) to a more $\mathrm{S_N1}$-type mechanism (with $\ce{AgCN}$). This has been challenged multiple times, and a review paper by H. Mayr, M. Breugst and A. Ofial sums up the evidence against it and provides a much more logical explanation.[1]
The first piece of evidence the authors present is the reaction of syn- and anti-2-bromo-3-(methylthio)butane. Thanks to neighbouring group effects, these two reactions all procede via an $\mathrm{S_N2}$-like transition state, yet the products are as expected as shown in scheme 1.
Scheme 1: Reaction of both the syn- and anti-isomers of 2-bromo-3-(methylthio)butane with $\ce{KCN}$ and $\ce{AgCN}$.[2]
Furthermore, Mayr et al. point out that even in cases where an $\mathrm{S_N1}$-like mechanism is impossible, such as the 1-chloroadamantane, isonitrile formation is possible using $\ce{TiCl4}$ and $\ce{TMSCN}$ in dichloromethane.[3]
The authors move on to explain the reactivity of the cyanide anion with their general nucleophilicity scale. In this, two parallel curves are given: one for carbon-attack whose reactivity is generally higher and one for nitrogen attack. They note:
From Figure 5 [sic!] one can extrapolate that the unsubstituted benzhydrylium ion ($E=5.9$), a-alkyl benzyl cations ($E$ ca. $3$ to $9$), and tertiary alkyl cations ($E$ ca. $8$) will undergo barrierless reactions with both termini of the free $\ce{CN}$ ion in acetonitrile.[1]
Thus, explaining the ambident reactivity of cyanide can be done on much simpler grounds. In most cases, the attack of the carbon atom to yield a nitrile is orders of magnitude faster than the attack of the nitrogen atom to yield an isonitrile. This changes once the diffusion barrier is reached for very strong electrophiles when both compounds should be obtained. To generate isonitriles, one needs to block the carbon centre. This can be done by using $\ce{TMSCN}$, where carbon is covalently bound to the $\ce{TMS}$ group’ silicon, or by using silver(I) salts. For these, strong silver-pseudohalide complexes are formed:
$$\ce{AgCN + CN- <=> [Ag(CN)2]-}$$
The strong silver–carbon bond prevents attack of the more reactive carbon centre.
References:
[1]: H. Mayr, M. Breugst, A. Ofial, Angew. Chem. Int. Ed. 2011, 50, 6470. DOI: 10.1002/anie.201007100.
[2]: J. C. Carretero, J. L. Garcia Ruano, Tetrahedron Lett. 1985, 26, 3381. DOI: 10.1016/S0040-4039(00)98303-5.
[3]: T. Sasaki, A. Nakanishi, M. Ohno, J. Org. Chem. 1981, 46, 5445. DOI: 10.1021/jo00339a050.