You have been taught that in some doubts about the number of the rak’ats of prayer you have to pray one or two rak’ats of Salat al-ihtiyat. Here I am explaining how to pray that prayer.
Soon after finishing the prayer (in which the doubt had occurred and which requires Salat al-ihtiyat for its completion and validation) without looking away from qibla or doing anything which makes a prayer invalid, you are to stand up and make the niyyah. (if the Salat al-ihtiyat is to be performed sitting, then remain sitting after the first prayer and make the niyyah). Niyyah is to be done in the following way: "I pray Salat al-ihtiyat one (or two) rak’at(s) wajib qurbatan ilal- Laah." Then say Takbiratul-Ihram. Recite only Surah al-Hamd in whisper. Go to ruku’ then do sajdah; recite tashahhud and salaam. Your Salat al-ihtiyat is finished.
If you have to recite two rakats of Salat al-ihtiyat, then you should stand up for the second rak’at just after the second sajdah of the first rak’at in the usual way. Recite the second rak’at also with just Surah al-Hamd, without even qunut, and then finish the prayer in usual way.
Sajdah al-sahw is wajib when:-
1. One has talked by mistake in prayer; or
2. Has left one sajdah by mistake; or
3. Has forgotten tashahhud by mistake; or
4. Has recited salaam by mistake at a wrong place; or
5. Has added or omitted by mistake any such thing which is not rukn; or
6. In the 4-rak’at prayer has doubt after the second sajdah whether it was the fourth or the fifth rak’at.
Soon after finishing the prayer, niyyah should be done as follows: " I do sajdah al-sahw in lieu of tashahhud (or salaam or sajdah or qiyam etc.. as the case may be) wajib qurbatan ilal-Laah." Then sajdah should be done. In Sajdah you have to say once "Bismillahi wa billahi Assalaamu alayka ayyuhan-Nabiyyu wa rahrnatullahi wa barakatuh." Then raise your head; sit properly; go to sajdah for the second time; recite the above-mentioned dhikr once; sit down properly; read tashahhud and salaam.
If you have forgotten tashahhud or one sajdah in the prayer, it is wajib to do its qada at once after the prayer; then the sajdah al-sahw is to be done just after the qada tashahhud or sajdah.
If after the prayer, but before the qada of the sajdah or the tashahhud, if any of such actions are done which invalidate the prayer (like turning away from qibla}, it is necessary to do the qada and the sajdah al-sahw as required, and then to repeat the prayer.