This question cuts to the heart of metabolism and homeostasis. It also highlights a fundamental fact. Except for oxygen, no substance is more important for sustaining multicellular life than water.
Obtaining Water
The vast majority of water in the human body is obtained from liquids in the diet. In addition to liquids, most solid foods contain some water, most notably fruits and vegetables. Beyond the diet, certain metabolic reactions produce small amounts of water. One example is protein synthesis, in which a water molecule is produced every time a peptide bond is formed. Similarly, a water molecule is released every time two glucose molecules are joined to form glycogen (starch) in the liver and skeletal muscles. However, because the reverse reactions (proteolysis and starch breakdown) consume water,
Retaining water
1) The kidneys, sodium, and urine production
A professor once remarked that the primary function of the kidneys is not to produce urine, but to retain sodium. By this, he meant that sodium retention is the body’s key to conserving water. This is the case because sodium ions are the predominant electrolyte in extracellular fluid, including blood plasma. Increased sodium retention results in increased water retention. As such, the body is equipped with powerful mechanisms to conserve sodium, most notably the renin-angiotensin-aldosterone axis.
When specialized cells in the kidney called the JGA (juxtaglomerular apparatus) detect a decline in blood flow through the renal vasculature, they release an enzyme called renin. This enzyme cleaves a protein called angiotensinogen into angiotensin 1 (AT-1). A second enzyme called ACE (angiotensin converting enzyme) cleaves AT-1 into angiotensin-2 (AT-2).
AT-2, in turn, stimulates the production of an adrenal hormone called aldosterone, which increases sodium retention in the kidneys. AT-2 also acts at the level of the brain by triggering the sensation of thirst. Finally, AT-2 (and possibly aldosterone) promote the release of yet another hormone called anti-diuretic hormone (ADH) from the posterior pituitary gland.
2) Blood Osmolality and ADH
Specialized regions of the brain called the subfornical organ (SFO) and vascular organ of the lamina terminalis (OVLT) detect blood osmolality, which can be thought of as viscosity. As a person becomes dehydrated, his/her blood becomes more viscous, or syrupy. At this point, the SFO and OVLT trigger certain hypothalamic neurons to release ADH from their axon terminals in the posterior pituitary. ADH travels back to the kidneys, where it signals collecting duct cells to insert special proteins called aquaporins in their membranes. Aquaporins act as water channels, removing water from the urine and diverting it back to the systemic circulation.
Losing water
In spite of the conservation mechanisms described above, most adults lose 1-2 liters of water per day through the urine alone. Besides urinary output, water also leaves the body in the form of insensible losses, an umbrella term encompassing water lost through sweating, as well as small amounts lost during exhalation.
In cold weather, relatively little water is lost in these ways. In hot weather, however, insensible water losses can add up quickly. To put it in perspective, at room temperature, people can live for 3 days or so without water. In contrast, people lost in the desert can die of dehydration in less than 24 hours unless they find water to drink.
The remaining important route of water loss is through the feces. Under normal circumstances, intestinal losses account for less than 100 ml of water lost each day. This amount increases dramatically in people who develop severe diarrhea, as for example during a cholera outbreak. According to WHO statistics, over 2 million people die of diarrheal illnesses each year, most of them children and the elderly.