Osmoregulation

Osmoregulation is how living things keep the right amount of salt and water in their bodies. All living things do this, from bacteria to humans.
The basic idea is that organisms keep osmotic pressure by controlling their water and salt concentrations. There are regulators and conformers. Conformers match their environment, and regulators do things which act to keep their internal water at a standard level of saltiness.
Sea fish, for example, tend to gain salt if they live in seawater. So they actively put out (excrete) salt from their gills. River fish, on the other hand, take the salt out before they excrete water. Some fish, like the flounder, live in both fresh and salt water at different stages in its life. They adapt to whichever water they are in.
Plants.
All plants regulate their water balance. Xerophytes like cacti keep water inside so they do not become too salty. Plants that live in seasonal wetlands also have ways of avoiding desiccation. Many plant leaves have a waterproof cuticle to regulate the loss of water, and use spiracles for gas exchange. Osmoregulation is an important aspect of homeostasis. it involves the balance between water and solute contents of cells.
Land animals.
The change from being in water to living on land was one of the most significant things which happened in evolution. From the perspective of water balance this was one of the most dramatic changes ever made. Suddenly, the new land animal had the problem of losing too much water through its skin, and taking in too little if it moved away from the water.
Kidneys.
Kidneys are the organ of osmoregulation in vertebrates, including humans. In the nephron, blood is filtered through the glomerulus. The filtrate, water, salts, and other small molecules, enters the tubule of the nephron. In excretion, the filtrate which remains in the tube leaves the kidney and becomes urine.
The amount of water reabsorbed is controlled by hormones such as antidiuretic hormone (ADH), aldosterone, and angiotensin II. For example, too high solute concentration in the blood (osmolarity) is detected by osmoreceptors in the hypothalamus (part of the brain). The hypothalamus then stimulates ADH release from the pituitary gland to make the walls of the collecting ducts more permeable to water. Therefore, more water is reabsorbed from fluid in the kidneys to prevent too much water from being excreted.
As an illustration of how universal osmoregulation is, bacteria also do it.
Sources.
Standard medical books of course have sections on the human kidney and the human water regulation. The complex details of hormone interaction is not covered in this brief summary.
Osmoregulation in animals generally is one of the issues surveyed in: