The water that fish live in, and even the water we drink is not pure H2O. It is the nature of water for mineral ions (Na+, K+, Mg2+, Cl- SO42- etc) to dissolve in it, in brief it is an excellent solvent. The ions that are dissolved in a body of water give it its ionic balance. Of course the same applies to the water that invests the cells of our, or a fish's body. We and the fish like to maintain the ionic concentrations, the ionic balance, of our personal waters at a level that is optimum for our biochemistry. For most species this internal balance is not in harmony with the balance of the environment. The mechanisms that fish use to maintain and internal ionic balance that is different to that of the water they are living in is called osmoregulation.
It is easy to understand that fresh and marine waters do not have the same ionic balance, although the balance that they do have is often fairly stable, but in places where they meet the ionic balance is often highly variable over time and place. All this makes problems for the fish, which over the millions of years of their evolution they have solved in a variety of ways. The ionic balance of sea water is about 1,000 milligrams of dissolved salts per litre, and that of freshwater normally around 8 to 10 milligrams of dissolved salts per litre or mgs/l.
Cell membranes and even the skin of fish is not 100% waterproof. We know that the basic physical laws of the universe tend to work towards creating an even homogeneous environment, they push towards a balance. Thus water naturally diffuses from an area of low ionic content towards an area of higher ionic concentration, and ions, if possible, diffuse from a high concentration towards a lower one.
What does this mean for a fish? It means that if the ionic content of the water it is living in is lower than the ionic content of its internal environment (fresh water) it will be constantly gaining water, some through its skin, but most through its gills. This gain in water will change its internal ionic balance and disrupt its metabolism. To avoid this happening it will need to be constantly pumping water out of its system. If however the ionic content of the water it is living in is higher than the ionic content of its internal environment (sea waters) it will be constantly losing water, and in order to stay alive it will need to drink the water it lives in, and because this water brings a lot of salts with it it will need to find a way to get rid of those excess salts.
You may have noticed that I said 'if' and 'if' in the previous paragraph. This is because not all fish are in one or either of these situations. It is possible to avoid confrontation with the environmental balance simply by maintaining an internal ionic balance that is the same as, or pretty close to that of the external environment and this is exactly what the Hagfish do. Their internal environment has an inorganic ionic balance of around 1,150 mgs/l. They are they only vertebrate to use this strategy, although it is common amongst invertebrates, which suggests that it is the old way of doing things, more modern animals have found that their metabolism works better with an inorganic ionic balance of around 350 mgs/l and so they strive to maintain this balance.
The ionic balance of a body of water is dependant on both its inorganic ions like those mentioned above, and on organic ions. The amount of organic ions is usually relatively low, but one group of mostly marine fish, the sharks and rays have evolved to use the organic ions that their body naturally creates to help them avoid dehydrating in the sea. The elasmobranchs, like the teleosts like to have an internal inorganic ion content of around 350 mgs/l, so to avoid conflict with sea they raise their overall ionic balance by maintaining a large amount of organic ions, mostly urea, but also some trimethylamine oxide in their water. A shark has a total ionic concentration of around 1,007 mgs/l. How they avoid poisoning themselves with the urea is a more complicated question that is beyond the scope of this introduction, but the trimethylamine oxide is an important factor.
This simple strategy is also used by the ancient Coelcanth (Latimera chalumnae) Interestingly the Bull Shark or Cub Shark (Carcharhinus leucas), a species that commonly frequents fresh waters as well as marine environments is able to adapt the amount of organic salts in its internal environment, a Bull Shark swimming 1,000 kilometres up a major river has a urea and TMAO balance of only one third of what it had when it was in the sea a month or two before.
The marine teleosts however have not gone along this path, they evolved another way of dealing with the imbalance. Their preferred internal ionic balance is about 350 mgs/l or one third of that of the sea. Therefore they are always losing water, they compensate for this by drinking water, but because the water is salty they now have too high a concentration of salts in their internal environment. They solve this problem by actively excreting salts in concentrated form back into the sea. This is not easy, it is like pushing pebbles up a hill, as soon as you stop pushing they all fall back down the slope again. To achieve their goal fish have special cells in their gill filaments and the skin of their opercular that concentrate salt and then excrete it. Because they are pushing against the gradient, this process uses up energy and a percentage of a fish's daily intake of food, and thus its energy, is spent on the constant battle to keep the salt out.
Freshwater teleosts obviously have a different problem, they are constantly absorbing water involuntarily and have to work to get rid of it again. They do this by producing copious quantities of dilute urine. A freshwater fish may produce the equivalent of 30% of its total body weight in urine every day. For example a 1 kg freshwater Pristis microdon, or Largetooth Sawfish produces about 250 millilitres of urine a day, in comparison a 1 kg marine Squalus acanthias or Piked Dogfish produces about 8 ml of urine a day and Scyliorhinus canicula or Small-spotted Catshark produces only 3 ml of urine a day.
Most of the later vertebrates like to maintain an internal ionic balance less than that of the teleost fishes, reptiles, amphibians, birds and mammals all have internal ionic concentration that are normally less than 300 mgs/l. Because the balance of life is so delicate, and because ionic interactions are so essential to life, so intricate a part of our essential biochemistry getting the best ionic environment is very important. It seems that the most complex life forms on this planet have found that ionic concentrations lower than that of sea water, but greater than that of fresh water are the most efficient to work with. In the fish we can see the direction of change from the earliest habit of simply putting up with the dictates of the external environment that the first fish inherited from their invertebrate ancestors towards the complex maintenance of an independent optimum internal ionic environment that is the legacy and blessing of our modern biochemistry.