Indeed, it seems likely that vertebrate life evolved when the oceans were approximately one quarter as salty as they are today. As the oceans became saltier and vertebrates evolved further, several groups of vertebrates (birds, mammals, reptiles and amphibians) left the oceans to inhabit the land masses, carrying the seawater with them as their blood. They maintained their blood salt concentrations by drinking freshwater and absorbing salts from food.
But fish stayed in the aquatic environment. To adapt, they had to either remain in low salinity environments, such as bays and estuaries, or they had to evolve mechanisms to replace water lost through osmosis to the seawater and to remove salts absorbed from the increasingly saline oceans. To inhabit freshwater, fish had to replace salts lost through diffusion to the water and eliminate excess water absorbed from the environment. Kidney function had to be altered accordingly for fish to survive in these different habitats.
In seawater, fish must drink salt water to replace lost fluids and then eliminate the excess salts. Their kidneys produce small volumes of fluid containing high concentrations of salt. Freshwater fish produce large volumes of dilute urine, which is low in salt. Less demand is placed on the kidneys to maintain stable concentrations of blood salts in brackish or low salinity waters.
Ultimately, fish adapted to or inhabited marine, fresh or brackish water because each environment offered some competitive advantage to the different species. For instance, it has been suggested that euryhaline fish are able to eliminate external parasites by moving to and from fresh and saltwaters. Habitats of differing salinity offered new or more food, escape from predators and even thermal refuge (stable temperatures).
Steven K. Webster, marine science advisor to the Monterey Bay Aquarium in California adds some perspective on fish that move between salt and freshwater.
The approximately 22,000 species of fishes alive today live in virtually all sorts of marine and aquatic habitats that are not unduly toxic. Some, including salmon, lampreys, shad, sturgeon and striped bass, move between freshwater bodies and the ocean at least once in their lives to spawn. Many of these anadromous species do so annually, finding conditions needed for reproduction in one realm and those needed for feeding and growth in the other.
These fishes have to switch over their salt balance physiology when they move from fresh to saltwater and back again. They typically make these adjustments in a brackish estuarine environment--which lies on the way between salt water and freshwater habitats.