A nucleophile is something which is attracted to, and then attacks, a positive or slightly positive part of another molecule or ion. All amines contain an active lone pair of electrons on the very electronegative nitrogen atom. It is these electrons which are attracted to positive parts of other molecules or ions.
The reactions of primary amines with halogenoalkanes
You get a complicated series of reactions on heating to give a mixture of products including secondary and tertiary amines and their salts, and quaternary ammonium salts.
Making secondary amines and their salts
In the first stage of the reaction, you get the salt of a secondary amine formed. For example if you started with ethylamine and bromoethane, you would get diethylammonium bromide
In the presence of excess ethylamine in the mixture, there is the possibility of a reversible reaction. The ethylamine removes a hydrogen from the diethylammonium ion to give free diethylamine - a secondary amine.
Making tertiary amines and their salts
But it doesn't stop here! The diethylamine also reacts with bromoethane - in the same two stages as before. This is where the reaction would start if you reacted a secondary amine with a halogenoalkane.
In the first stage, you get triethylammonium bromide.
There is again the possibility of a reversible reaction between this salt and excess ethylamine in the mixture.
The ethylamine removes a hydrogen ion from the triethylammonium ion to leave a tertiary amine - triethylamine.
Making a quaternary ammonium salt
The final stage! The triethylamine reacts with bromoethane to give tetraethylammonium bromide - a quaternary ammonium salt (one in which all four hydrogens have been replaced by alkyl groups).
This time there isn't any hydrogen left on the nitrogen to be removed. The reaction stops here.
The reactions of amines with acyl chlorides
We'll take the reaction between methylamine and ethanoyl chloride as typical. If you add concentrated methylamine solution to ethanoyl chloride, there is a violent reaction in the cold. N-methylethanamide and methylammonium chloride are formed - partly as a white solid mixture, and partly in solution. The overall equation is:
\[ CH_3COCl + 2CH_3NH_2 \rightarrow CH_3CONHCH_3 + CH_3NH_3Cl\]
The reactions of amines with acid anhydrides
These reactions are chemically similar to those between amines and acyl chlorides, but they are much slower, needing heat. Taking the reaction between methylamine and ethanoic anhydride as typical. The product is N-methylethanamide (as with ethanoyl chloride), but this time the other product is methylammonium ethanoate rather than methylammonium chloride.
\[ (CH_3CO)_2O + 2CH_3NH_2 \rightarrow CH_3CONHCH_3 + CH_3COO^- + ^+N_3CH_3\]
Jim Clark (Chemguide.co.uk)