Habits are your brain’s version of autopilot. They allow you to get ready for work, navigate your way to the office, and find your way home without having to reinvent the wheel every day. They save time and energy . . . except when they involve grabbing a candy bar from the vending machine every afternoon at 3 p.m. In cases like this, bad habits can feel like a battle of wills.

To find out why some habits can be hard to make or break, researchers from the University of California performed experiments with mice and found that the brain’s circuits for habit- and goal-directed action compete for control in the area of the brain that makes decisions.

“Neurochemicals called endocannabinoids allow for habit to take over by acting as a sort of brake on the goal-directed circuit,” writes Christina Gremel, an assistant professor of psychology at the University of California San Diego who headed up the study that was published in the research journal Neuron.

Endocannabinoids are chemicals that are naturally produced by humans and animals, and receptors are found throughout the body and brain. This system is involved in a variety of physiological processes, such as appetite, pain sensation, mood, and memory.

Earlier studies found that the orbitofrontal cortex (OFC) is the part of the brain that relays goal-directed information. When researchers increased the output of neurons in the OFC in mice using optogenetics–a technique that involves flashes of light–goal-directed actions also increased. And when they decreased activity in the OFC using chemicals, the mice acted on habit.

A good balance of habitual and goal-directed actions helps with everyday functioning and task management. “We need to be able to make routine actions quickly and efficiently, and habits serve this purpose,” writes Gremel. “However, we also encounter changing circumstances, and need the capacity to ‘break habits’ and perform a goal-directed action based on updated information.”

The brain shifts from habit to goal-directed behavior when we need to drive to a different location, for example. The decision to make or break a habit also relies on goal-directed behavior in the beginning. Healthy mice had no problem shifting from one type to the other, but people with conditions such as obsessive-compulsive disorder and addiction may have a physical problem that inhibits goal-directed action, the study suggests. “It does appear some things we think of as more maladaptive like addiction seem to have a bias toward habit system,” Gremel says. “The goal-directed system is still there, and you can still rescue it. Treatment could be pharmaceutical or might involve behavioral therapy. Further research is needed.”