The kidneys are a pair of organs of the excretory system in vertebrates, which maintain the balance of water and electrolytes in the body (osmoregulation), filter the blood, remove metabolic waste products, and, in many vertebrates, also produce hormones (in particular, renin) and maintain blood pressure. In healthy vertebrates, the kidneys maintain homeostasis of extracellular fluid in the body. When the blood is being filtered, the kidneys form urine, which consists of water and excess or unnecessary substances, the urine is then excreted from the body through other organs, which in vertebrates, depending on the species, may include the ureter, urinary bladder, cloaca, and urethra.
All vertebrates have kidneys. The kidneys are the main organ that allows species to adapt to different environments, including fresh and salt water, terrestrial life and desert climate. Depending on the environment in which animals have evolved, the functions and structure of the kidneys may differ. Also, between classes of animals, the kidneys differ in shape and anatomical location. In mammals, they are usually bean-shaped. Evolutionarily, the kidneys first appeared in fish as a result of the independent evolution of the renal glomeruli and tubules, which eventually united into a single functional unit. In some invertebrates, the nephridia are analogous to the kidneys but nephridia are not kidneys. The metanephridia, together with the vascular filtration site and coelom, are functionally identical to the ancestral primitive kidneys of vertebrates.