At about the same time, the company’s staff psychologists were beginning to extend their understanding of how habits are formed.

“For most of our history, we’ve sold newer and better products for habits that already existed,” said Dr. Berning, the P.& G. psychologist. “But about a decade ago, we realized we needed to create new products. So we began thinking about how to create habits for products that had never existed before.”

Academics were also beginning to focus on habit formation. Researchers like Wendy Wood at Duke University and Brian Wansink at Cornell were examining how often smokers quit while vacationing and how much people eat when their plates are deceptively large or small.

Those and other studies revealed that as much as 45 percent of what we do every day is habitual  that is, performed almost without thinking in the same location or at the same time each day, usually because of subtle cues.

For example, the urge to check e-mail or to grab a cookie is likely a habit with a specific prompt. Researchers found that most cues fall into four broad categories: a specific location or time of day, a certain series of actions, particular moods, or the company of specific people. The e-mail urge, for instance, probably occurs after you’ve finished reading a document or completed a certain kind of task. The cookie grab probably occurs when you’re walking out of the cafeteria, or feeling sluggish or blue.

Our capacity to develop such habits is an invaluable evolutionary advantage. But when they run amok, things can become tricky.

Consider a series of experiments Dr. Wansink performed with a bowl of tomato soup that was secretly connected to a tube that pumped more and more liquid into the bowl. Diners ended up eating almost twice as much soup as usual, though they didn’t report feeling any fuller after the meal.