If a congregant is uncertain whether he joined the imam in the first or second rakʿah, he should count it as the second; and if he doubts whether he actually caught that rakʿah at all, he must disregard it and, in both cases, perform the prostration of forgetfulness.
Should he be unsure whether he has left out a pillar, the ruling is as though he truly omitted it: he must carry it out together with whatever follows, following the details already given.
If he doubts whether he has omitted a wajib component, this misgiving is ignored and no prostration of forgetfulness is required. The same holds if he suspects that he added something, for the default assumption is that no addition has occurred.
These are some of the rulings on the prostration of forgetfulness. Whoever seeks further detail should consult the legal manuals, and Allah is the one who grants success.