Short answer
You should not. In the Hanafi school starting a prayer while you urgently need to urinate, open your bowels or pass wind is makruh tahrimi, even if it means missing the congregation; relieve yourself first. Only if the prayer's time is about to run out do you pray as you are. Food that is ready while you are hungry is similar.
Praying while holding back the call of nature is makruh tahrimi, and such a prayer should be repeated within its time. If the urge comes during the prayer and distracts you, break it, relieve yourself, make wudu and start again. If waiting would make the time pass, pray as you are.
The four schools agree on this.
Explanation
The Prophet ﷺ said there is no prayer when food is served, nor while a person is resisting the two calls of nature. Prayer needs a present heart, and someone squirming to hold on cannot focus. The four schools agree that this is disliked.
- Before the prayer: go to the toilet first and renew wudu, even if you will miss the congregation. You can join late or pray alone.
- During the prayer: if the urge becomes strong and takes your mind off the prayer, it is better to break it, relieve yourself and start again.
- Time running out: if relieving yourself would make the prayer's time pass, pray as you are.
- A mild urge that does not distract you is not a problem.
Food and hunger. If food has been served and you are hungry, eat first, so long as the prayer time is not running out. This is not a licence to schedule meals over prayer times; it is about not praying with your mind on your plate.
If you have a condition that makes you leak or need to go constantly, the rules are different; see praying with urine leakage. For what breaks the prayer, see what breaks your salah.
The evidence
Sahih Muslim 560
Sahih... لا صلاة بحضرة الطعام ولا هو يدافعه الأخبثان ...
"There is no prayer when food is served, nor while one is resisting the two calls of nature."
Praying while holding back the toilet, or hungry with food ready, is disliked.
Where the ruling is recorded
- Nur al-Idah with Maraqi al-Falah, Chapter on what is disliked in prayer. Praying while resisting urine, stool or wind is disliked.
- Radd al-Muhtar (Ibn Abidin), Kitab al-Salah, chapter on what is disliked in prayer. It is makruh tahrimi; break the prayer if the urge distracts, unless time is short.
Checked by our team. For a more accurate answer to your own situation, consult a scholar. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.