Ketone bodies are produced mainly in the mitochondria of liver cells, and synthesis can occur in response to an unavailability of blood glucose, such as during fasting. Other cells, e.g. human astrocytes, are capable of carrying out ketogenesis, but they are not as effective at doing so. Ketogenesis occurs constantly in a healthy individual. Ketogenesis in healthy individuals is ultimately under the control of the master regulatory protein AMPK, which is activated during times of metabolic stress, such as carbohydrate insufficiency.  Its activation in the liver inhibits lipogenesis, promotes fatty acid oxidation, switches off acetyl-CoA carboxylase, turns on malonyl-CoA decarboxylase, and consequently induces ketogenesis.  Ethanol is a potent AMPK inhibitor and therefore can cause significant disruptions in the metabolic state of the liver, including halting of ketogenesis, even in the context of hypoglycemia.
Ketogenesis takes place in the setting of low glucose levels in the blood, after exhaustion of other cellular carbohydrate stores, such as glycogen. It can also take place when there is insufficient insulin (e.g. in type 1 (and less commonly type 2) diabetes), particularly during periods of "ketogenic stress" such as intercurrent illness.
The production of ketone bodies is then initiated to make available energy that is stored as fatty acids. Fatty acids are enzymatically broken down in β-oxidation to form acetyl-CoA. Under normal conditions, acetyl-CoA is further oxidized by the citric acid cycle (TCA/Krebs cycle) and then by the mitochondrial electron transport chain to release energy. However, if the amounts of acetyl-CoA generated in fatty-acid β-oxidation challenge the processing capacity of the TCA cycle; i.e. if activity in TCA cycle is low due to low amounts of intermediates such as oxaloacetate, acetyl-CoA is then used instead in biosynthesis of ketone bodies via acetoacetyl-CoA and β-hydroxy-β-methylglutaryl-CoA (HMG-CoA). Furthermore, since there is only a limited amount of coenzyme A in the liver, the production of ketogenesis allows some of the coenzyme to be freed to continue fatty-acid β-oxidation. Depletion of glucose and oxaloacetate can be triggered by fasting, vigorous exercise, high-fat diets or other medical conditions, all of which enhance ketone production. Deaminated amino acids that are ketogenic, such as leucine, also feed TCA cycle, forming acetoacetate & ACoA and thereby produce ketones. Besides its role in the synthesis of ketone bodies, HMG-CoA is also an intermediate in the synthesis of cholesterol, but the steps are compartmentalised. Ketogenesis occurs in the mitochondria, whereas cholesterol synthesis occurs in the cytosol, hence both processes are independently regulated.