Nitriles, also classified as carboxylic acid derivatives, are commonly prepared by dehydration of amides. The reaction requires strong dehydrating agents like phosphorous pentoxide or boiling acetic anhydride. Similarly, thionyl chloride is another important dehydrating agent used for preparing nitriles. The mechanism begins with a nucleophilic attack by the amide on the thionyl chloride, forming an intermediate. Next, the electron pairs are rearranged with the departure of a chloride ion as a leaving group. Further deprotonation removes the positive charge on the nitrogen atom. Lastly, a second deprotonation releases sulfur dioxide and chloride ion, giving nitrile as the final product. Notably, nitriles are also prepared by reacting alkyl halides with a cyanide ion, forming a new carbon–carbon bond. The reaction follows the SN2 mechanism, thereby requiring primary or unhindered secondary alkyl halides, but tertiary alkyl halides cannot be used.