The Shulhan Aruch (O.H. 7:1) states that any time one relieves oneself throughout the day, one recites the blessing of Asher Yatzar, and does not recite “Al Netilat Yadayim” (except when one washes after waking up in the morning). Asher Yatzar gives praise to Hashem for the different wonders and intricacies of the human body. The Shulhan Aruch does not mention the amount of time one has to recite this blessing after relieving oneself, but the contemporary Poskimdo shed light on this.
The Ben Ish Hai (Parashat Vayetze, § 2) and Rabbi Ben Zion Abba Shaul (Or LeZion, vol. II, ch. 1, § 19) both rule that Asher Yatzar has to be recited “close to” when one relieves oneself, which they interpret as being within thirty minutes. If one did not recite in within that timeframe, one would not be permitted to recite for that particular instance. Nevertheless, the Siddur Bet Oved, which was commonly used in Morocco, cites a handwritten responsum from Rabbi Eliezer Nahum which says that one may recite Asher Yatzar as long as one does not need to use the restroom again. The Sha’are Teshuva (O.H. 7:1) and the Mishna Berura (O.H. 7:1) both quote this opinion and Rabbi Ovadia Yosef (Yabia Omer, vol. VIII, Orah Haim, § 22:2) writes that this is the Halacha and further brings proof from the Ritva (Pesahim 46) who says that even though Asher Yatzar is a blessing of thanksgiving, there is no issue in reciting it at anytime after one uses the restroom. Practically speaking, Rav Ovadia writes that one has at least 72 minutes, equivalent to the time it takes to walk a Parsa.
Summary: If one did not recite Asher Yatzar immediately, one may still recite it within 72 minutes. If one did not recite it within this timeframe, there is a Halachic basis to permit reciting it later than this time, so long as one does not feel the urge to relieve oneself again.