From daily tooth-brushing to the 11am coffee, we all have dozens of habits that get us through our daily routine.

Some are great - weekly gym visits are often encouraged - others not so much, like smoking a pack a day, or dialling the number of the pizza place way too often.

Because we recognise our habits as useful or detrimental behaviours, we often strive to shape them accordingly.

There's no shortage of apps out there designed to help you form a habit, and many of those are built on the assumption that all you need is 21 days.

This number comes from a widely popular 1960 book called Psycho-Cybernetics by Maxwell Maltz, a plastic surgeon who noticed his patients seemed to take about 21 days to get used to their new faces.

However, according to a 2009 study, the time it takes to form a habit really isn't that clear-cut.

Researchers from University College London examined the new habits of 96 people over the space of 12 weeks, and found that the average time it takes for a new habit to stick is actually 66 days; furthermore, individual times varied from 18 to a whopping 254 days.

The take-away message here is that if you want to develop a new behaviour, it will take at least two months, and you shouldn't despair if three weeks doesn't do the trick - for most people that's simply not enough.

Stick with it for longer, and you'll end up with a habit you can keep without thinking.

But what about trying to break an unwanted habit?

It turns out the two - habit forming and breaking - can be quite closely linked.

As psychologist Timothy Pychyl explains to Alison Nastasi at Hopes and Fears, they're two sides of the same coin: "Breaking a habit really means establishing a new habit, a new pre-potent response. The old habit or pattern of responding is still there (a pattern of neuron responses in the brain), but it is less dominant (less potent)."

"It's much easier to start doing something new than to stop doing something habitual without a replacement behaviour," says neuroscientist Elliot Berkman.

"That's one reason why smoking cessation aids such as nicotine gum or inhalers tend to be more effective than the nicotine patch."

Experts agree that there's no typical time frame for breaking a habit, and the right recipe is going to be a mix of personality, motivation, circumstances, and the habit in question.

"People who want to kick their habit for reasons that are aligned with their personal values will change their behaviour faster than people who are doing it for external reasons such as pressure from others," says Berkman.

According to psychology professor Susan Krauss Whitbourne, sometimes a habit can be broken quickly: "In extreme cases, the habit can be broken instantly, such as if you happen to become violently ill when you inhale cigarette smoke or nearly get hit by a bus when texting and walking."

But in most cases it's going to take longer than that, and you should probably allow for at least two months.

To successfully break a habit, you need to think of your strongest motivation, which will drive you along.

Think of a 'replacement behaviour' for the habit, but make sure it's a positive one - replacing smoking with snacking is a common trap, for example.

And be patient. The longer you've had a habit, the longer it will take to get rid of it.

"Longtime habits are literally entrenched at the neural level, so they are powerful determinants of behavior," explains Berkman.

"The good news is that people are nearly always capable of doing something else when they're made aware of the habit and are sufficiently motivated to change."

So stay strong, you can do it.

A version of this article was first published in September 2015.