Sheikh Khâlid al-Mushaykih, professor at al-Imâm University, al-Qasîm branch
The Prophet (peace be upon him) said: “Prayer in congregation is twenty seven times better than prayer prayed individually.” [Sahîh al-Bukhârî (645) and Sahîh Muslim (650)]
It would seem that this is only for the congregational prayer with the appointed imam.
It is clear from the Sunnah that this distinction is only for the group who pray with the appointed imam in the mosque and not for any other congregation. This is because the hadîth is an encouragement to attend the congregational prayer at the mosque with the appointed imam.
If someone prays with a group of people other than the congregation in the mosque with the appointed imam then he will receive the reward of praying with a group but not the reward of the proper congregational prayer at the mosque.
The Prophet (peace be upon him) said: “The prayer of a man with another man is better than his praying alone, and the prayer of a man with two other men is better than his praying alone or with only one other man, and the more people there are, the more beloved it is to Allah.” [Sunan al-Nasâ’î (843) and Sunan Abî Dâwûd (554)]
And Allah knows best.
Source: Islam Today