The excretory system is a passive biological system that removes excess, unnecessary materials from the body fluids of an organism, so as to help maintain internal chemical homeostasis and prevent damage to the body. The dual function of excretory systems is the elimination of the waste products of metabolism and to drain the body of used up and broken down components in a liquid and gaseous state. In humans and other amniotes (mammals, birds and reptiles), most of these substances leave the body as urine and to some degree exhalation, mammals also expel them through sweating.
 Only the organs specifically used for the excretion are considered a part of the excretory system. In the narrow sense, the term refers to the urinary system. However, as excretion involves several functions that are only superficially related, it is not usually used in more formal classifications of anatomy or function.
 As most healthy functioning organs produce metabolic and other wastes, the entire organism depends on the function of the system. Breaking down of one of more of the systems is a serious health condition, for example kidney failure.
 The kidneys are large, bean-shaped organs which are present on each side of the vertebral column in the abdominal cavity. Humans have two kidneys and each kidney is supplied with blood from the renal artery. The kidneys remove from the blood the nitrogenous wastes such as urea, as well as salts and excess water, and excrete them in the form of urine. This is done with the help of millions of nephrons present in the kidney. The filtrated blood is carried away from the kidneys by the renal vein (or kidney vein). The urine from the kidney is collected by the ureter (or excretory tubes), one from each kidney, and is passed to the urinary bladder. The urinary bladder collects and stores the urine until urination. The urine collected in the bladder is passed into the external environment from the body through an opening called the urethra.
 The kidney's primary function is the elimination of waste from the bloodstream by production of urine. They perform several homeostatic functions such as:-
 The way the kidneys do this is with nephrons. There are over 1 million nephrons in each kidney; these nephrons act as filters inside the kidneys. The kidneys filter needed materials and waste. Needed materials go back into the bloodstream; unneeded materials become urine and are expelled through the urethra.
 In some cases, excess wastes crystallize as kidney stones. They grow and can become painful irritants that may require surgery or ultrasound treatments. Some stones are small enough to be forced into the urethra.
 The ureters are muscular ducts that propel urine from the kidneys to the urinary bladder. In the human adult, the ureters are usually 25–30 cm (10–12 in) long. In humans, the ureters arise from the renal pelvis on the medial aspect of each kidney before descending towards the bladder on the front of the psoas major muscle. The ureters cross the pelvic brim near the bifurcation of the iliac arteries (which they run over). This "pelviureteric junction" is a common site for the impaction of kidney stones (the other being the uteterovesical valve). The ureters run posteriorly on the lateral walls of the pelvis. They then curve anteriormedially to enter the bladder through the back, at the vesicoureteric junction, running within the wall of the bladder for a few centimeters. The backflow of urine is prevented by valves known as ureterovesical valves. In the female, the ureters pass through the mesometrium on the way to the bladder.
 The urinary bladder is the organ that collects waste excreted by the kidneys prior to disposal by urination. It is a hollow muscular, and distensible (or elastic) organ, and sits on the pelvic floor. Urine enters the bladder via the ureters and exits via the urethra.
 Embryologically, the bladder is derived from the urogenital sinus, and it is initially continuous with the allantois. In human males, the base of the bladder lies between the rectum and the pubic symphysis. It is superior to the prostate, and separated from the rectum by the rectovesical excavation. In females, the bladder sits inferior to the uterus and anterior to the vagina. It is separated from the uterus by the vesicouterine excavation. In infants and young children, the urinary bladder is in the abdomen even when empty.
 In anatomy, the (from Greek – ourethra) is a tube which connects the urinary bladder to the outside of the body. In humans, the urethra has an excretory function in both genders to pass.
 One of the main functions of the lungs is to diffuse gaseous wastes, such as carbon dioxide, from the bloodstream as a normal part of respiration.
 The large intestine's main function is to transport food particles through the body and expel the indigestible parts at the other end, but it also collects waste from throughout the body. The typical brown colour of mammal waste is due to bilirubin, a breakdown product of normal heme catabolism. The lower part of the large intestine also extracts any remaining usable water and then removes solid waste. At about 10 feet long in humans, it transports the wastes through the tubes to be excreted.
 The liver detoxifies and breaks down chemicals, poisons and other toxins that enter the body. For example, the liver transforms ammonia (which is poisonous) into urea in fish, amphibians and mammals, and into uric acid in birds and reptiles. Urea is filtered by the kidney into urine or through the gills in fish and tadpoles. Uric acid is paste-like and expelled as a semi-solid waste (the "white" in bird excrements). The liver also produces bile, and the body uses bile to break down fats into usable fats and unusable waste.
 Invertebrates lack a liver, but most terrestrial groups, like insects, possesses a number of blind guts that serve the similar functions. Marine invertebrates do not need the ammonia conversion of the liver, as they can usually expel ammonia directly by diffusion through the skin.
 Sweat glands in the skin secrete a fluid waste called sweat or perspiration; however, its primary functions are temperature control and pheromone release. Therefore, its role as a part of the excretory system is minimal. Sweating also maintains the level of salt in the body.
 In mammals, the skin excretes sweat through sweat glands throughout the body. The sweat, helped by salt, evaporates and helps to keep the body cool when it is warm. In amphibians, the lungs are very simple, and they lack the necessary means to the exhale like other tetrapods can. The moist, scale-less skin is therefore essential in helping to rid the blood of carbon dioxide, and also allows for urea to be expelled through diffusion when  submerged.
 In small-bodied marine invertebrates, the skin is the most important excretory organ. That is particularly true for acoelomate groups like cnidarians, flatworms and nemerteans, who have no body cavities and hence no body fluid that can be drained or purified by nephrons, which is the reason acoelomate animals are thread-like (nemertans), flat (flatworms) or only consist of a thin layer of cells around a gelatinous non-cellular interior (cnidarians).
 Like sweat glands, eccrine glands allow excess water to leave the body. The majority of eccrine glands are located mainly on the forehead, the bottoms of the feet, and the palms, although the glands are everywhere throughout the body. They help the body to maintain temperature control. Eccrine glands in the skin are unique to mammals.[citation needed]
 Secretions of sweat from the eccrine glands play a large role in controlling the body temperature of humans. Regulation of body temperature, also known as thermoregulation, is very important when it comes to instances that bring the body's temperature outside of the homeostatic temperature such as with a fever or even exercise. Together these glands make up the size of about one kidney and in one day a human can perspire amounts as much as 10 liters. The two functions consist of secretion of a filtrate in response to acetylcholine and reabsorption of sodium near the duct when there is water in excess so that a sweat can be surfacing the skin.
 There are three parts to the eccrine sweat gland and these are the pore, the duct, and the gland. The pore is the portion that goes through the outermost layer of the skin and is typically 5-10 microns in diameter. The duct is the part of the sweat gland that connects dermis cells to the epidermis. It is composed by two layers of cells and is between 10 and 20 microns in diameter. The gland does the actual secretion and it lies deep within the dermis. The cells that make up the gland are larger in size than the duct cells and its lumen is around 20 microns in diameter.
 After bile is produced in the liver, it is stored in the gall bladder. It is then secreted within the small intestine where it helps to emulsify fats in the same manner as a soap. Bile also contains bilirubin, which is a waste product.
 Bile salts can be considered waste that is useful for the body given that they have a role in fat absorption from the stomach. They are excreted from the liver and along with blood flow they help to form the shape of the liver where they are excreted. For instance, if biliary drainage is impaired than that part of the liver will end up wasting away.
 Biliary obstruction is typically due to masses blocking the ducts of the system such as tumors. The consequences of this depend on the site of blockage and how long it goes on for. There is inflammation of the ducts due to the irritation from the bile acids and this can cause infections. If rupture of the duct takes place it is very traumatic and even fatal.
 Within the kidney, blood first passes through the afferent artery to the capillary formation called a glomerulus and is collected in the Bowman's capsule, which filters the blood from its contents—primarily food and wastes. After the filtration process, the blood then returns to collect the food nutrients it needs, while the wastes pass into the collecting duct, to the renal pelvis, and to the ureter and are then secreted out of the body via the urinary bladder.
 Scientifically, masses referred to as a renal calculus or nephrolith, or more commonly, "kidney stones", are solid masses of crystals that may be a variety of shapes, sizes, and textures, that can reside within one or both of the kidneys. Kidney stones form when the balance is off between the concentration of substances that pass through urine, and the substances that are supposed to dissolve them. When substances are not properly dissolved, they have the ability to build up, and form these kidney stones. These stones are most commonly made up of substances such as calcium, cystine, oxalate, and uric acid, as these are the substances that normally would dissolve within the urine. When they do not dissolve correctly and further build up, they will commonly lodge themselves in the urinary tract and in this case, are usually small enough to pass through urine. In extreme situations, however, these stones may lodge themselves within the tube that connects the kidney and the bladder, called the ureter. In this case, they become very large in size and will most likely cause great pain, bleeding, and possibly even block the flow of urine. These can occur in both men and women, and studies show that around 12% of men, and 8% of women in America will develop kidney stones within their lifetime.
 In those extreme situations, in which kidney stones are too large to pass on their own, patients may seek removal. Most of these treatments involving kidney stone removal are done by a urologist; a physician who specializes in the organs of the urinary system. A common way of removal is shock wave lithotripsy, in which the urologist will shock the kidney stone into smaller pieces via laser, allowing these pieces to further pass through the urine on their own, as a normal case of kidney stones. Larger, more serious cases may demand Cystoscopy, Ureteroscopy, or Percutaneous Nephrolithotomy, in which the doctor will use a viewing tool or camera to locate the stone, and based on the size or situation, may either chose to continue with surgical removal, or use the shock wave lithotripsy treatment. Once the kidney stone(s) are successfully eliminated, the urologist will commonly suggest medication to prevent future recurrences.
 Pyelonephritis is a type of urinary tract infection that occurs when bacteria enters the body through the urinary tract. It causes an inflammation of the renal parenchyma, calyces, and pelvis. There are three main classifications of pyelonephritis: acute, chronic and xanthogranulomatous.
 In acute pyelonephritis, the patient experiences high fever, abdominal pain and pain while passing urine. Treatment for acute pyelonephritis is provided via antibiotics and an extensive urological investigation is conducted to find any abnormalities and prevent recurrence.
 In chronic pyelonephritis, patients experience persistent abdominal and flank pain, high fever, decreased appetite, weight loss, urinary tract symptoms and blood in the urine. Chronic pyelonephritis can also lead to scarring of the renal parenchyma caused by recurrent kidney infections.
 Xanthogranulomatous pyelonephritis is an unusual form of chronic pyelonephritis. It results in severe destruction of the kidney and causes granulomatous abscess formation. Patients infected with Xanthogranulomatous pyelonephritis experience recurrent fevers, anemia, kidney stones and loss of function in the affected kidney.
 A urine culture and antibiotics sensitivity test is issued for patients who are believed to have pyelonephritis. Since most cases of pyelonephritis are caused from bacterial infections, antibiotics are a common treatment option. Depending on the species of the infecting organism and the antibiotics sensitivity profile of the organism, treatments may include fluoroquinolones, cephalosporins, aminoglycosides, or trimethoprim individually or in combination. For patients with xanthogranulomatous pyelonephritis, treatment might include antibiotics as well as surgery. Nephrectomy is the most common surgical treatment for a majority of cases involving xanthogranulomatous pyelonephritis.
 In men, roughly 2-3 cases per 10,000 are treated as outpatients and 1 in 10,000 cases require admission to the hospital. In women, approximately 12–13 in 10,000 cases are treated as outpatients and 3-4 cases are admitted to a hospital. The most common age group affected by Xanthogranulomatous pyelonephritis is middle-aged women. Infants and elderly are also at an increased risk because of hormonal and anatomical changes.