Aldehydes and ketones react with halogens in acidic or basic media, producing the substitution of hydrogens for halogens.

Halogenation of propanone in an acid medium:

halogenacion01.gif
The halogenation mechanism in an acid medium has the following stages:

Stage 1. Formation of the enol
halogenacion02.gif

Stage 2. Nucleophilic attack of the enol on the halogen aided by the transfer of oxygen para.
halogenacion03.gif

Stage 3. Deprotonation
halogenacion04.gif
Working with an equivalent of reagent, the halogenation stops in a first addition and polyalogenations do not occur. The key step in the mechanism is the formation of the enol and this step requires protonation of the carbonyl oxygen. Once halogenated, the oxygen position becomes less basic, due to the electronegative effect of bromine, protonating worse.

Halogenation of propanone in basic medium :
halogenacion-acido05.gif

Halogenation in a basic medium has the following mechanism:

Stage 1. Formation of the enolate
halogenacion-acido06.gif

Stage 2. Nucleophilic attack of the enolate on the halogen aided by the transfer of oxygen para.
halogenacion-acido07.gif

This mechanism is repeated another 5 times, replacing all the hydrogens with halogens. In this case the reaction does not stop since the halogenated product is more reactive than the starting propanone. The base removes the hydrogens in the halogenated product better (they are more acidic), making it impossible to stop the reaction.