Economic theories of rational addiction aim to describe consumer behavior in the presence of habit-forming goods. We provide a biological foundation for this body of work by formally specifying conditions under which it is optimal to form a habit. We demonstrate the empirical validity of our thesis with an in-depth review and synthesis of the biomedical literature concerning the action of opiates in the mammalian brain and their effects on behavior. Our results lend credence to many of the unconventional behavioral assumptions employed by theories of rational addiction, including adjacent complementarity and the importance of cues, attention, and self-control in determining the behavior of addicts. Our approach suggests, however, that addiction is "harmful" only when the addict fails to implement the optimal solution. We offer evidence for the special case of the opiates that harmful addiction is the manifestation of a mismatch between behavioral algorithms encoded in the human genome and the expanded menu of choices generated for example, by advances in drug delivery technology faced by consumers in the modern world.