Acid chlorides can be prepared from carboxylic acids by treating the acid with a chlorinating agent such as thionyl chloride (SOCl2), phosphorus trichloride (PCl3), or phosphorus pentachloride (PCl5). The reaction generally proceeds via nucleophilic acyl substitution where the hydroxyl group of the carboxylic acid is replaced by a chlorine atom, releasing SO2 and HCl with SOCl2, or POCl3 and HCl with PCl3/PCl5. This reaction is favored due to the formation of these volatile byproducts, which drive the reaction to completion.