Ketone bodies
The name is misleading, we talk about bodies because at the beginning they were thought to be insoluble in water and to precipitate but in reality they turned out to be very soluble, moreover not all ketone bodies are actually ketones. Acetone and acetoacetate are actually ketone groups, but in beta-hydroxybutyrate the ketone group is replaced by an alcoholic group.
Ketogenesis occurs only in the mitochondria of hepatocytes and to a lesser extent in the renal cortex when there is an accumulation of acetyl-CoA, for example when there are many fatty acids and few sugars as happens in fasting.
If there is no oxaloacetate, acetyl-CoA cannot enter in Krebs cycle and it accumulates, ketogenesis is not harmful per se but it becomes so only if it is too excessive.
The first reaction of ketogenesis is a condensation reaction of two molecules of acetyl-CoA that, not being able to enter the Krebs cycle, bind together and form acetoacetyl-CoA by the enzyme thiolase (it is the same enzyme of the last reaction of beta oxidation but it works in reverse).
In the second reaction acetoacetoacetyl-CoA reacts with a third molecule of acetyl-CoA to give beta-hydroxy-beta-methylglutaryl-CoA (HMG-CoA) and a second free CoA, the enzyme is HMG-CoA synthase, here ATP is not hydrolyzed because the energy for the reaction is obtained from the breaking of the CoA bond.
In the third reaction HMG-CoA lyase detaches acetyl-CoA and acetoacetate is formed, the first of the ketone bodies.