Read Talmud Berachot 60b on Sefaria for the surrounding biblical/liturgical context.
The blessing first appears in the Talmud, tractate Berachot 60b, in the form roughly identical to what is said today. The Talmud also gives the rationale: "For Rabbi Abahu said: One should not say a blessing over something that has not yet occurred, but one should say a blessing over something that has just occurred. So after a bathroom visit, one says Asher Yatzar." The blessing is for what just didn't go wrong.
Modern physicians, especially gastroenterologists and urologists, have come to love Asher Yatzar as a precise description of human physiology: the body is described as having nekavim (openings) and chalulim (hollow organs/cavities). Both kinds of structures are essential. If any of the openings (sphincters, valves) opens or closes wrongly, exactly the failure mode of incontinence, hernias, fistulas, intestinal obstruction, the body cannot function. "It would be impossible to exist and stand before You."
The closing line, "rofei chol basar u'mafli la'asot" ("Healer of all flesh, acting wondrously"), has become a phrase Jewish doctors invoke before surgery, before consultations, in medical research. It frames medicine as participation in God's healing work; it frames the body's daily functions as an ongoing miracle.
Judaism, unlike some other religious traditions, does not regard the body as a lower or shameful counterpart to the soul. The body is the soul's partner, both created with chochmah (skilled wisdom), both essential to a person's standing before God. Asher Yatzar is one of the clearest liturgical articulations of this: the body's plumbing matters theologically. Forgive the body's needs; honor them; thank God for their proper functioning.
This is why some traditional Jewish texts treat the bathroom itself as a sacred space requiring care (modesty, certain blessings before/after) rather than a shameful one. The blessing of the body is just as important as the blessing of the soul.