Amides are formed by the reaction of carboxylic acids with ammonia, primary and secondary amines. The reaction is carried out under heating.

At low temperatures, amines react with carboxylic acids as bases and not as nucleophiles.
 
synthesis-amides
 
This acid-base reaction is impaired when heated, predominating under these conditions the nucleophilic attack that will form the amide.
 
synthesis-amides
 
The reaction mechanism occurs in the following stages:
 
Stage 1. Addition of ammonia to the carboxylic group
 
synthesis-amidessynthesis-amides
 
Stage 2. Acid-base balance to transform the -OH into a good leaving group
 
synthesis-amides
 
Stage 3. Water removal
 
synthesis-amides