Recall that direct alkylation of ammonia gives a mixture of 1°-, 2°-, and 3°-amines. To exclusively make primary amines, phthalimide—a protected form of ammonia comprising only one acidic N–H proton capable of single alkyl substitution is used. Gabriel synthesis uses phthalimide, a base, and hydrazine to convert alkyl halides into primary amines. In the first step, phthalimide's N–H proton is abstracted by a base, resulting in a resonance-stabilized nucleophilic anion. The anion attacks the alkyl halide in an SN2 fashion to give N-alkyl phthalimide, which, despite the nitrogen's lone pair, does not get alkylated due to its reduced nucleophilicity. In the next step, hydrazine attacks one of the carbonyl groups, performing a nucleophilic acyl substitution to cleave the C–N bond. An intramolecular N–N proton transfer, followed by another nucleophilic acyl substitution by the unreacted –NH2 of hydrazine, forms a charged cyclic compound while simultaneously kicking off the amine with a negative charge on nitrogen. The negative nitrogen deprotonates the positive nitrogen to give a primary amine and a stable phthalimide hydrazide.