When twitching of the arms and legs occurs during sleep, a number of possible factors should be considered. First of all, it is necessary to rule out the possibility of seizures, which can be caused by congenital factors or infectious diseases of the brain, such as viral encephalitis. It may also be caused by intracranial tumor lesions. You need to go to the neurology department of a hospital in time to have an EEG, CT or MRI done to determine the treatment plan according to the test results. Twitching of hands and feet while sleeping may also be caused by calcium deficiency, which can be clarified by electrolyte examination. For calcium deficiency, it can be improved by the usual diet, for example, you can eat more beans, milk and other calcium-rich foods.