Nucleophilic substitution mechanism

Steps of nucleophilic substitution
Nucleophile approaches the haloalkanes with a partially positive C atom
Nucleophile donates its lone pair to the C atom forming a new covalent bond
Original bond between the C atom and the halogen breaks heterolytically as the halogen atom takes both shared electrons
Halogen is replaced by the nucleophile
Types of nucleophiles
Reaction with hydroxide to form alcohols
Haloalkanes undergo nucleophilic substition with aqueous hydroxide ions from bases like sodium hydroxide when the mixture is warmed
C2H5Br + OH- → C2H5OH + Br-

This reaction replaces the haloalkane with an alcohol product, is a type of hydrolysis reaction. Water molecule also act as a nucleophile in similar hydrolysis reactions with haloalkanes to generate alcohols. However, the reaction rate is much slower with neutral water molecules than hydroxide ions, which are more nucleophilic
Reaction with cyanide to form nitriles

Reaction with ammonia to form amines
When heated under pressure with excess ethanolic ammonia, haloalkanes undergo nucleophilic substitution to form primary amines
C2H5Br + 2NH3 → C2H5NH2 + NH4Br

Initially the ammonia replaces the bromine atom. Subsequently, it abstracts the hydrogen from the intermediate amine, yielding the final amine product alongside ammonium bromide