Nucleophilic substitution of alkyl halides:
The mechanism is much similar with nucleophiles like ammonia or amines - the only variation being that a salt is formed and an extra step is needed in order to gain the free amine. As an instance, we shall consider the reaction among the ammonia and 1-iodopropane. The nitrogen atom of ammonia is the nucleophilic center for this reaction and uses its lone pair of electrons to make a bond to the alkyl halide. As a result, the nitrogen will successfully lose an electron and will gain a positive charge. The C-I bond is broken like previously explained and an iodide ion is formed like a leaving group that then acts as a counterion to the alkylammonium salt. The free amine can be acquired by reaction with sodium hydroxide. This neutralizes the amine to the free base that becomes insoluble in water and precipitates like a solid or as an oil.
Figure: SN2 mechanism for the reaction of 1-iodopropane with ammonia.
The reaction of ammonia along with an alkyl halide is a nucleophilic substitution as far as the alkyl halide is concerned. Though, similar reaction can be viewed as an alkylation from the ammonia's point of view. This is since the ammonia has acquired an alkyl group from the reaction. Primary alkyl halides go through the SN2 reaction faster as compared to secondary alkyl halides. Tertiary alkyl halides react very slowly if at all.