Fidgeting is a response to anxiety or boredom. Anxious fidgeting occurs because the body has elevated levels of stress hormones, which are prepping your muscles for sudden exertion. If you don’t have any tigers to run away from at that moment, all that energy has nowhere to go and jiggling your leg or biting your nails is a way to partially relieve that.
Research at the University of Hertfordshire in 2005 found that fidgeting improved performance in memory tests and this might be because it lowers the level of cortisol, a stress hormone that interferes with learning. Boredom fidgeting such as drumming your fingers or pen spinning gives your brain something to focus on. This is soothing and reduces the amount of other, less directed, fidgeting.