A haloform reaction is a chemical reaction during which a methyl ketone is halogenated by chlorine, bromine or iodine in the presence of a base to form a haloform. A haloform is an alkyl halide.
In addition to a methyl ketone, acetaldehyde can also undergo a haloform reaction. During the reaction, a hydroxyl ion from the base in the reaction removes a hydrogen atom from the methyl group of the ketone and forms water. Once the hydrogen is removed, the carbon in the methyl group has a lone pair of electrons that can form a bond with a halogen atom. Another hydroxyl ion removes a second hydrogen from the methyl group, thus creating space for one more halogen to bond with the lone pair of electrons generated on the carbon of the methyl group.
This whole process is repeated one more time to remove the last hydrogen from the methyl group and replace it with a third halogen atom. To remove the haloform from the ketone, the hydroxyl group forms a bond with the ketone, and through the rearrangement of electrons, the carbon with the three halogen atoms is removed. This carbon has a lone pair of electrons that are used to form a bond with a hydrogen atom from the hydroxyl group to complete the haloform reaction.