Sayyiduna Mu'adh bin Jabal (may Allah be pleased with him) said: We used to come to the prayer, and when a man came having missed part of the prayer, the one next to him would indicate to him that he had missed so many (rak'ahs), and then he would make them up (afterwards). (Mu'adh, may Allah be pleased with him) said: So (at one and the same time) some of us would be bowing, some prostrating, some standing and some sitting. One day I came having missed part of the prayer, and I was shown by gesture how much I had missed. I said: In whatever position I find him (the Prophet, peace and blessings be upon him), I join him in that position. So I joined in the very position in which I found them. When the Messenger of Allah (peace and blessings be upon him) had finished the prayer, I stood up and prayed (the rest). The Messenger of Allah (peace and blessings be upon him) turned to face the people and said: "Who was the one who said such and such?" The Companions said: Mu'adh bin Jabal. He (peace and blessings be upon him) said: "Mu'adh has set this way for you, so follow him. When one of you comes having missed part of the prayer, let him pray his (remaining) prayer with the imam, and when the imam finishes, let him make up what he missed."
Hadith Referenceالمعجم الكبير للطبراني / باب الميم / 17407