The World Federation One Stop Fiqh

Ruling 1204

If before performing ṣalāt al-iḥtiyāṭ one realises that the number of rakʿahs he performed was less than the required number, in the event that he has not done anything that invalidates prayers, he must perform whatever he has not performed; then, based on obligatory precaution, he must perform sajdatā al‐sahw for saying an additional salām. However, if he has done something that invalidates prayers – for example, he turned his back to qibla –  he must perform the prayer again.