It’s not uncommon to get leg cramps when starting a ketogenic diet. In fact, leg cramps are one of the classic symptoms of the keto flu (a popular term for the group of unpleasant side effects that may occur when you are transitioning your body from a high-carb diet to a low-carb, higher fat, moderate protein diet). But this doesn’t mean you have to suffer through them. Here we share what causes leg cramps on a keto diet and what you can do to get rid of them. Hint: It’s easy! 

What Causes Leg Cramps on Keto

Keto-related leg cramps are typically due to an essential mineral imbalance (usually magnesium but also possibly sodium and potassium) as well as dehydration. This imbalance tends to occur only before your body begins regularly leveraging ketones for energy rather than glucose. You can experience cramps any time of day or night if you experience them at all. 

Electrolyte (Mineral) Imbalance

When you eliminate carbs from your diet, your body produces less insulin (insulin’s job is to process carbs). With far less carbs to process, your body produces (and uses) significantly less insulin. The lessening of insulin in your system triggers your kidneys to absorb less sodium, so more is released in your urine. This can trigger a sodium deficiency and a consequent electrolytes imbalance.

What exactly are electrolytes? Electrolytes are positively charged minerals that help with hundreds of processes within the body, mostly with the muscles and nerves. They’re found in pretty much all of your bodily fluids (sweat, urine, and blood). Their primary function is to push fluid in and out of the cells (aka keep you hydrated), contracting and relaxing muscles, and nerve conduction. The main electrolytes involved in keto-related leg cramps are potassium, magnesium, and sodium. (You can learn more about each of these electrolytes below.)


When you’re converting from using glucose to ketones for energy, your body first uses up all of its glycogen (glucose) stores. Glycogen is attached to water in the body, so when it begins using its glycogen stores, it frees up the excess water to be eliminated from the body through urination. This is the reason many people lose a lot of weight fast when beginning a keto diet; your stored water (bloating) is making an exit. But, this can also lead to dehydration. 


Other Reasons for Muscle Cramps

There are a few other factors that might be giving you muscle cramps, including too much caffeine, exercising and not drinking enough to make up for sweating (dehydration), or sitting for too long without moving your body. 


Drinking too much coffee can increase your chance of leg cramps when you start a keto diet because caffeine stimulates your muscles to contract and is also a diuretic, so it takes water out of your body, which can lead to dehydration and cramping.

Exercising without hydrating

When you sweat you lose both water and electrolytes, which is why there’s such a big market for sports drinks (unfortunately, sports drinks aren’t keto-friendly because they’re very high in sugar).

Sitting for too long

Many people with an electrolyte imbalance get worse leg cramps at night (nocturnal leg cramps) due to a lack of movement during the day. When you aren’t moving, your muscles can get tighter and can “seize up” on you. This is why getting up and walking sometimes helps to stop a “charley horse” (leg cramp). 

How to Remedy or Avoid Muscle Cramps When Starting Keto 

Now that you know what causes leg cramps, what can you do to fix them or avoid getting them in the first place? We have some simple solutions to help you get those leg cramps under control quickly. Let’s start with the minerals.

Ensure You’re Getting Enough Potassium

Potassium controls the cells energy. It helps to pump energy going in and out of the cells. Potassium is a big “muscle mineral” that allows your muscles to fully relax, or not go into a cramp. Potassium works in harmony with the other electrolytes for muscle contraction and relaxation. So, when you are deficient you may get muscle cramps. 

  • How can you be sure you’re getting enough potassium? Eat lots of leafy green vegetables, and stick to a clean keto diet as much as possible. The best keto-friendly foods with potassium are beet greens, swiss chard, spinach, mushrooms, brussels sprouts, zucchini, broccoli, and asparagus. 

Ensure You’re Getting Enough Magnesium

Magnesium is a very important (4th abundant) mineral in your body, yet, most of us are deficient due to modern farming practices (depleted soils). You may eat a clean keto diet, high in vegetables, yet still be deficient in magnesium. Magnesium is a co-factor (helper) mineral that helps with over 300 enzymatic processes within the body. Magnesium is involved with anything nerve or muscle related and is known as the relaxation mineral.

But magnesium and calcium play together. Magnesium and calcium are teammates when it comes to muscle and nerve function. Calcium contracts muscles, magnesium relaxes them. The typical American diet is very high in calcium and low in magnesium. When you don’t get enough magnesium to balance calcium, too much calcium can get into the muscles and contract them, and there isn’t enough magnesium to relax them, so you get those dreaded cramps. 

  • How can you be sure you’re getting enough magnesium in your diet? Like potassium, magnesium is found in clean, whole foods. The best keto-friendly food sources of magnesium are hemp, spinach, avocado, swiss chard, chia seeds, and pumpkin seeds. Because you may struggle to get enough magnesium from food alone, there are supplement sources of magnesium that can be helpful as well. 

Ensure You’re Getting Enough Sodium

Sodium pushes fluid in and out of the cell walls and is a co-factor in muscle contraction. You need it to maintain fluid levels in and around your cells. Sodium also helps keep the balance of the other electrolytes. As we mentioned above, when you convert to keto you lose fluids and thus lose sodium. This is why many experience “keto flu” symptoms such as headache, nausea, dizziness and heart palpitations, all of which are related to sodium loss. 

How can you be sure you’re getting enough sodium? We recommend adding a pinch of Himalayan salt to your water or food, especially when transitioning into keto. (Learn more about differences between various types of salt here.) This helps tremendously with your sodium levels as your body adjusts to the transition of ketones over glucose for energy. 

Stay Hydrated!

The easiest thing you can do is drink water throughout the day. Drink at least half of your body weight in ounces of water throughout the day. For example, if you weigh 150 pounds, you will want to drink 75 ounces of water. On top of this amount, if you drink diuretics, such as coffee, increase your water intake by 1-1/2 cups of water per cup of coffee. 

If you’re physically active on keto, be sure to hydrate before, during, and after your exercise session, and add a pinch of Himalayan salt to your water. You might want to try adding mineral drops to your water, which typically contain concentrated trace minerals. Another option is to use a keto-friendly sports electrolyte powder—these are great for after exercising or sweating a lot. 

Keep Moving

Remember, sitting for too long can give you leg cramps too. If you sit at a desk all day, be sure to get up and move your body a few times throughout the day. Consider setting an alarm to walk around and stretch a bit every two hours. Stretching out before bed can help loosen any tight areas in your muscles as well, especially if you exercise.

The biggest takeaway here? Keep those electrolytes in check, and stay hydrated. If you’re struggling with painful leg cramps on the keto diet, hopefully these tips will stop them in their tracks. 

Keto-Mojo is a participant in some affiliate programs and some of the links above will generate a small commission if you make a purchase through a product link on our site. This is at no cost to you and all proceeds go directly to the nonprofit Ketogenic Foundation [501(c)3 pending] to assist with their mission funding education and research into the ketogenic diet and lifestyle. Keto-Mojo in no way profits from these links.



Not on our mailing list?
Sign up and get 3 Easy, Gourmet Keto-Mojo Dinner Recipes!

At Keto-Mojo, we believe in sharing—sharing important keto community news, science and studies, great keto recipes, products we love, and profiles of people that inspire us.

Join our community now and get 3 exclusive recipes not found on our website.

Show Buttons
Hide Buttons