Imine formation is acid-catalyzed and reversible, and its mechanism has two parts. The first part begins with a nucleophilic attack of the amine to generate a dipolar intermediate. Mildly acidic ammonium ion, generated from the amine and a strong acid, further catalyzes the reaction by protonating the intermediate, followed by deprotonation to give a carbinolamine. In the second part, the hydroxyl group is protonated to make a better leaving group to facilitate the further reaction. The loss of water forms an iminium ion, which subsequently deprotonates to produce an imine. The pH of the solution dictates the overall rate of imine formation. The first step proceeds slowly under strongly acidic conditions where most amine molecules are protonated and non-nucleophilic, incapable of attacking the carbonyl group. Under strongly basic conditions, the fourth step is slow due to excess base and no proton donors, thereby inhibiting protonation of the carbinolamine and consequently the formation of iminium ions. To summarize, imine formation is the slowest at low and high pH values and fastest at around pH 4.5.