We were with the Prophet ﷺ when he said, "Whoever among you is able to marry should do so, for it lowers the gaze and guards the private parts. Whoever is unable to marry should fast, for fasting is a shield for him."
كنا مع النبي ﷺ فقال: من استطاع الباءة فليتزوج، فإنه أغض للبصر، وأحصن للفرج، ومن لم يستطع فعليه بالصوم فإنه له وجاء.
Bukhari reported it in the Book of Fasting (1905), and Muslim in the Book of Marriage (1400), both through the route of Amash, from Ibrahim, from Alqama, who said, "While I was walking with Abdullah he said (then he mentioned it)." The wording given is Bukhari's. In Muslim's version there is the story of Ibn Masud with Uthman
.His statement, "he has a wija" is with a kasrah on the waw, meaning the crushing of the testicles, though it is also said to mean the crushing of their veins. Whoever has this done to him loses his sexual desire, and the implication is that fasting suppresses the desire for marriage. (See Fath al-Bari 4/119).