All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
Sujood As-Sahw (prostration of forgetfulness) is performed as two prostrations at the end of the prayer. It is to be performed in three cases:
1) When an extra action is added to the prayer. If a worshipper added an extra Rak‘ah, Rukoo‘ (bowing), or Sujood (prostration) to the prayer, he is required to perform Sujood As-Sahw at the end of the prayer.
2) When an action is omitted from the prayer. If a worshipper forgetfully fails to perform an obligation of the prayer, like omitting the transitional Takbeer or the Tasbeeh in Rukoo‘ or Sujood, for example, it is prescribed for him to perform Sujood As-Sahw to amend the shortage in the prayer.
3) When he doubts about performing a particular action in the prayer. If a worshipper doubts whether he performed three or four Rak‘ahs, for instance, he should assume that he performed three (the lesser number), and act accordingly [i.e. perform the missing Rak’ah], and then perform Sujood As-Sahw at the end of the prayer.
Muslim scholars agreed that a worshipper’s prayer is valid whether he performs Sujood As-Sahw before or after Tasleem (concluding the prayer with Salaam). However, they held different opinions about which is better. The Shaafi'i School of jurisprudence maintained that it is better to perform Sujood As-Sahw before Tasleem, and the Hanbali School agreed with them in this regard, except in the case when a worshipper recites Tasleem before performing all the required acts of the prayer. According to the Hanbali School, the worshipper is required, in this case, to perform Sujood As-Sahw after Tasleem.
The Hanafi School of jurisprudence, on the other hand, held that Sujood As-Sahw should be performed after Tasleem in all cases.
The Maaliki School of jurisprudence maintained that if a worshipper added an extra action to the prayer, Sujood As-Sahw should be performed after Tasleem; and if he omitted an action from the prayer, Sujood As-Sahw should be performed before Tasleem. This last opinion was considered the preponderant opinion by many researching scholars (well-versed), as it carries a very strong authoritative weight.
Lastly, it is worth highlighting that there are many rulings pertinent to Sujood As-Sahw; it is advisable that you refer to the relevant Fataawa that we have previously posted for more benefit.
You may refer for instance to Fataawa 83932, 89546 and 370321.
Allah Knows best.