Have you ever tried to break a bad habit, only to give up in frustration? The problem isn’t that you’re weak or that the bad habit is too ingrained; in all likelihood, you just gave up too soon.

Researchers at University College, London, found that it takes 66 days for a new habit to form. Likewise, as long as there is no physical addiction involved, it takes 66 days for you to shake a bad habit. But before you can develop the motivation to stick it out for that long, you need to understand how bad habits form in the first place.

Related: 10 Research-Proven Tricks to Seem Smarter Than You Are

Bad habits are formed and reinforced via the habit loop. First, something triggers you to initiate an undesired behavior. Maybe you’re feeling stressed, so you decide to numb out on Facebook for an hour or eat a whole bag of Flamin’ Cheetos. The trigger event is whatever puts this idea in your head. The second step is the behavior itself. Your brain says, “Sure, you deserve some Flamin’ Cheetos,” so you dig in.

The third step -- and this part is crucial -- is the reward. The behavior has to reward you in some way. That doesn’t mean it’s good for you or that it’s smart, just that it does something that your brain likes. Numbing out on Facebook might help you forget your problems for a while or to put off something that you don’t want to do, and we all know, all too well, the reward that comes from eating a bag of junk food. For better or worse, these rewards increase the likelihood that you’ll repeat the behavior.

Once you repeat a behavior enough times, the habit loop becomes so automated that you don’t even think about it anymore. Instead of making a conscious decision to procrastinate, you just automatically pull up Facebook as soon as you sit down at your desk or you’re digging into the Cheetos before you even realize that you’re feeling stressed.

Once a habit becomes automatic, it’s a lot harder to break -- and that’s why you’re probably failing if you’re not giving yourself 66 days to wean yourself off it.

Related: Breaking These 13 Bad Habits Will Make You Happier

Sixty-six days might seem like a long time, but there are specific stages you have to go through that will make the process feel much shorter. Let’s take a look at these.

Days 1-10: Look inward

It’s usually pretty obvious which bad habits are causing the most problems in your life -- the ones that keep coming up in performance appraisals or sparking arguments with your spouse. Once you’ve identified a habit to change, the real challenge lies in understanding your triggers, and that can be harder than it sounds, especially if the habit has become so ingrained that you do it subconsciously. If you give it enough thought, you’ll get to the bottom of it. Maybe you keep getting tickets for speeding, and you realize that you drive too fast when you leave work in a bad mood, or maybe you snack when you’re stressed. Looking inward to explore the source of the habit you’re trying to break makes breaking that habit possible. The first 10 days of trying to break the habit will provide substantial insight into the source of the habit, should you choose to look.

Days 11-40: Spread the word

Accountability is crucial in breaking bad habits. In this stage, you create a very vocal accountability network by telling everybody you can about the habit you’re trying to break, and the more vocal you are about it, the more likely people are to call you out when you slip up. Let them know that you really want them to say something. Just remember that you might have to keep reminding them -- it’s just as easy for them to forget and backslide as it is for you to do so.

Days 41-66: Mind your relapse triggers

As you head for the home stretch, be ready to make some mistakes -- it happens to everybody. Just be on the lookout for common threads running through those mistakes. If you tend to relapse in a certain situation, you’d be smart to avoid that trigger completely until you feel that your bad habit is really extinguished. Keeping your triggers from surprising you when it feels like you’ve kicked the habit is typically the difference between success and failure this late in the process.

Related: 10 Rules for Beating Stress

Day 67: Reward yourself

Sure, you could say that breaking the habit is its own reward, but why pass up an opportunity to celebrate? Just don’t celebrate by indulging in the habit you worked so hard to break! You should also use this opportunity to reflect and select the next habit you’re going to break.

Bringing It All Together

You’re not weak, stupid, or lazy if you have a hard time breaking bad habits. There are psychological factors that make this process challenging for everyone, but the very science behind what makes habits hard to break also provides a research-supported method for doing it. Focus on one habit at a time and follow these steps and the timetable that goes with them, and your chances of success will go through the roof.

A version of this article appeared on TalentSmart.

The animated video in this article was produced by www.VerveVideos.com in collaboration with Entrepreneur Media Inc.