The purpose of this blessing is to thank God for good health.[1] It expresses thanks for having the ability to excrete, for without it existence would be impossible.[3]
Though recited normally by observant Jews each time excretory functions are used, it is also recited during the Shacharit service due to its spiritual significance (to Jews, humans are made in God's image, so it is an expression of awe toward God's creations).[3]
Sources
The obligation to recite a blessing upon leaving the bathroom could be traced to the following passage in Berachot (60b):[4]
One who enters a latrine should say [to the ministering angels who accompany him], "Be honored, honored and holy ones who serve the Most High! Give glory to the God of Israel; leave me while I enter and do my will [i.e., relieve myself], then I will come to you."
Abaye objects to saying the above, and suggests one should recite something else prior to relieving oneself as well as recite a blessing similar to Asher Yatzar upon exiting the latrine.
Abaye said: A person should not speak like this, for they might leave him and go; rather, he should say, "Guard me, guard me, help me, help me, support me, support me, wait for me, wait for me until I enter and come out, for this is the way of human beings." When he comes out, he says, "Blessed... who has formed man with wisdom and created within him many openings and hollow spaces. It is obvious and known before Your Seat of Honor, that if even one of them would be opened, or one of them would be sealed, it would be impossible [to survive and] to stand before You."
A dispute over what the conclusion (chasima) of the blessing should be is recorded:
How is it to be concluded? Rav said, "who heals the sick." Shmuel said: Does Abba [Rav] regard the whole world as sick? Rather, [the conclusion of the benediction should be] "who heals all flesh." Rav Sheshet said "who acts wondrously." Rav Papa said: Let us therefore say both: "who heals all flesh and acts wondrously."
After completing urination or defecation and upon leaving the bathroom, the person washes their hands. According to Jewish etiquette, this should be done outside the bathroom, but if there is no source of water available outside the bathroom, it is permissible to wash one's hands inside the bathroom, then dry them outside; some are lenient in modern bathrooms to wash in the bathroom, as our bathrooms are much more clean than the outhouses of the olden days. No al netilat yadayim blessing is recited for the handwashing.[2]
Following the washing and drying of one's hands, the asher yatzar blessing is recited.
Text
English [Presented in Nusach Sfarad; see footnotes for other Nuschaot]
"Blessed are You, Adonai, our God, King of the universe, Who formed man with wisdom and created within him many openings and many hollow spaces. It is obvious and known before Your Seat of Honorthat if even one of them would be opened, or if even one of them would be sealed, it would be impossible to survive and to stand before Youeven for one hour. Blessed are You, Adonai, Who heals all flesh and acts wondrously."
Hebrew [Presented in Nusach Sfarad; see footnotes for other Nuschaot]
There is no consensus as to whether or not (or how often) a person with medical issues should recite Asher Yatzar:[5]
A person with incontinence should recite the blessing after urination, even if it is involuntary
One who has no bowel or bladder control does not recite the blessing at all
One who, as a result of medication feels an interrupted need to urinate, should recite the blessing a single time after they have emptied their bladder
One who has a urinary catheter is considered to engage in a single act of urination lasting the entire day, so the catheter's wearer should recite the blessing once in the morning with the intent that it apply to all urination for the entire day.
One who has diarrhea should recite the blessing after each instance of diarrhea
One who has taken a laxative should not recite the blessing until the laxative has taken effect
One whose mind is not completely settled due to illness is exempt