Leg twitching when you lie down is extremely common and almost always harmless. The most likely explanation depends on what the twitching actually feels like: a single sudden jerk as you drift off to sleep, a persistent crawling urge to move, or small visible flickers in the muscle itself. Each points to a different cause, and most can be managed with simple changes.
Hypnic Jerks: The Jolt as You Fall Asleep
If your legs (or whole body) twitch with a single strong jerk right as you’re falling asleep, you’re experiencing a hypnic jerk, sometimes called a sleep start. These happen because the brainstem, which manages the transition from wakefulness to sleep, fires off a sudden burst of nerve signals during that handoff. Your brain is essentially stumbling as it switches modes, and the result is a brief, involuntary muscle contraction.
Hypnic jerks are more frequent when you’re overtired, stressed, or have had caffeine or nicotine close to bedtime. Vigorous exercise late in the evening can also make them worse. They’re not a sign of a neurological problem. If they bother you, the fix is usually straightforward: cut caffeine after early afternoon, keep a consistent sleep schedule, and give yourself a wind-down period before bed.
Restless Legs Syndrome
Restless legs syndrome (RLS) feels different from a simple twitch. It’s a deep, uncomfortable sensation in the legs, often described as crawling, pulling, or aching, paired with an almost irresistible urge to move. Four features define it:
- The urge to move starts or worsens when you’re resting, especially lying down.
- Moving, stretching, or walking temporarily relieves it.
- It’s worse in the evening and at night.
- It’s not explained by another condition like a leg cramp or positional discomfort.
The underlying cause involves dopamine, a brain chemical that helps regulate movement. In people with RLS, dopamine signaling in the brain appears to be underactive, and this dysfunction follows a circadian pattern, getting worse as the day goes on and easing with physical activity. That’s why symptoms peak right when you’re trying to sleep.
Iron plays a direct role in dopamine production, so low iron stores are one of the most treatable contributors. Specialists recommend iron supplementation for anyone with RLS whose ferritin level (a blood marker of iron stores) is at or below 75 ng/mL. If your legs are restless most nights, a simple blood test can determine whether low iron is part of the picture.
Periodic Limb Movements During Sleep
Some people don’t notice the twitching themselves but are told by a partner that their legs jerk repeatedly throughout the night. This is periodic limb movement disorder (PLMD), a condition where the legs flex in a rhythmic, stereotypical pattern during sleep, typically involving the foot dorsiflexing and the big toe extending. The movements recur every 5 to 90 seconds, often in clusters.
PLMD is diagnosed through a sleep study. To meet the clinical threshold, adults need to have more than 15 of these movements per hour, and the movements must be disrupting sleep quality or causing daytime fatigue. Many people have occasional periodic limb movements that show up on a sleep study without causing any problems, so the movements alone don’t automatically mean you have a disorder.
Benign Fasciculations
If what you’re noticing is a small, visible flicker or ripple under the skin of your calf, thigh, or foot while you’re lying still, that’s a fasciculation. It’s a tiny cluster of muscle fibers firing on their own. Benign fasciculation syndrome causes these twitches to recur for weeks, months, or even years without any other symptoms. They tend to happen most in the calves, and they’re more noticeable at rest because you’re not using the muscle and your attention isn’t directed elsewhere.
The key distinction is that benign fasciculations involve twitching only. There’s no weakness, no muscle shrinking, and no difficulty with coordination. The twitches also tend to appear in one spot in one muscle at a time. Stress, caffeine, and fatigue can all increase their frequency. Some people also notice muscle cramps alongside the twitching, a variant called cramp-fasciculation syndrome.
Magnesium and Electrolyte Imbalances
Magnesium helps keep nerve cells from firing too easily. At the junction where a nerve meets a muscle, magnesium reduces the muscle’s sensitivity to nerve signals. When magnesium levels drop, that natural brake weakens, and nerves become hyperexcitable, firing spontaneously and producing twitches, jerks, and sometimes cramps.
Low magnesium can cause twitching in the arms, legs, and even the face. In more significant deficiency, you might also notice muscle stiffness or spasms. People who sweat heavily, drink alcohol regularly, or take certain medications (like proton pump inhibitors for acid reflux) are more prone to running low. Magnesium-rich foods include dark leafy greens, nuts, seeds, and beans, though a supplement may help if dietary intake is consistently low.
Medications That Can Trigger Leg Twitching
Several common medication classes can cause or worsen nighttime leg movements. Antidepressants are the most frequently reported culprit, particularly SSRIs like fluoxetine and citalopram, SNRIs like venlafaxine and duloxetine, and mirtazapine. These drugs alter brain chemistry in ways that can disrupt dopamine signaling and trigger restless legs symptoms.
Antipsychotic medications work by blocking dopamine receptors directly, which explains their strong association with restless legs. Anti-nausea drugs that block dopamine, like metoclopramide, can do the same thing, though symptoms typically resolve after stopping the medication.
Over-the-counter antihistamines deserve special attention because so many people take them as sleep aids. Diphenhydramine, the active ingredient in many nighttime cold and sleep products, is significantly associated with restless legs symptoms. If you’ve started taking an OTC sleep aid and noticed your legs are more restless, the antihistamine itself may be the cause.
What Helps at Home
For occasional twitching that isn’t linked to a specific condition, a few strategies consistently help. Walking or stretching for a few minutes before bed can settle overactive nerves. Some people find that a warm bath relaxes the muscles enough to reduce twitching, while others prefer a cool compress on the legs.
Cutting caffeine and nicotine, especially after midday, reduces both hypnic jerks and restless legs symptoms. Keeping a regular sleep schedule matters more than most people expect, because sleep deprivation is one of the strongest triggers for all types of nighttime twitching. If you suspect low magnesium or iron, those are straightforward to check with a blood test and relatively easy to correct.
Signs That Need Medical Attention
Muscle twitching becomes a concern when it arrives suddenly and is accompanied by weakness, loss of muscle tone, or visible shrinking of the muscle. Twitching in the tongue is almost always worth investigating, as it can signal motor neuron involvement. If you notice that the muscle around the twitch is getting weaker or smaller over weeks, or if you’re developing trouble with coordination, speech, or swallowing alongside the twitching, those are red flags that warrant a neurological evaluation.
For the vast majority of people, though, leg twitching at bedtime is the body’s way of reacting to fatigue, stress, minor nutritional gaps, or the simple neurological hiccup of falling asleep. It looks and feels alarming, but it rarely signals anything serious.

