The muscles in our body move our joints around by flexing and contracting, it is when a muscle spasms into the contracted state that we get a cramp. Medical science does know that there are three major factors that contribute to cramps, hydration, fatigue, and conditioning. Our body runs on a very complex system of chemical reactions. In the simplest form potassium and sodium molecules swap sides on the surface of a cell carrying poisons out and nutrients in. When we get dehydrated this process can slow and the poisons, including nitrogen get trapped in the cells.
Hydration is very simple to solve.
Drink a lot of fluid. Under normal conditions you should drink about one quart of water for each hour of hiking or physical activity you are involved in, more under hot, cold, or extremely dry conditions and when at high altitude. You should also eat from 250 to 400 calories during that hour. Your water bottle in your pack does not help you reach this goal. Carry a water bottle with you where it is easily accessible or even better invest in a hydration pack that allows you to sip water at will.