Modim is an especially important prayer. One must concentrate on both the modim in the silent shemoneh esrei as well as the modim d’rabanan in the same attentive and reverent manner that one is required to concentrate on the avot blessing of the shemoneh esrei. The congregation recites modim d’rabanan quietly and concurrently with the chazzan when he recites modim in the repetition of the shemoneh esrei. The modim d’rabanan, as its name implies, was essentially co-authored by a number of different sages. As the Talmud states:
When the leader recites modim, what does the congregation recite?
Rav said, "We give thanks to You, O Lord our God, for giving us the ability to thank You."
Shmuel said, "God of all flesh, we thank you for giving us the ability to thank You."
Rav Simai said, "Our Creator and Creator of all things from time immemorial, we give You thanks."
The Nehardeans said in the name of Rav Simai, "Blessings and thanksgiving to Your great Name because You have kept us alive and preserved us, and we give You thanks.”
Rav Acha bar Yaakov used to conclude his prayer like this, "So may You continue to keep us alive and be gracious to us and gather us together and assemble our exiles to Your holy court, to observe Your laws and to perform Your will with a perfect heart, and we give You thanks."
Rav Papa said, "Let us recite all of these prayers!”
Indeed, as Rav Papa concludes, the modim d’rabanan text that is used today is essentially a compilation of all these prayers, though there are some minor variations between the different nusachot.
There is, however, much discussion on how the modim d’rabanan should be concluded. According to some authorities, it should conclude with the formula "Baruch Ata Hashem El Hahodaot," similar to all the other blessings of the shemoneh esrei.Other authorities disagree, arguing that there is no reason to conclude modim d’rabanan with God’s name as if one were reciting a blessing. Common custom is in accordance with this view and modim d’rabanan is simply concluded with "Baruch El Hahodaot.” So too, the words at the very end of modim d’rabanan should read "she'anachnu modim lach" and not "she'anu modim lach" as is found in some siddurim. This is because the word "anu" is not found anywhere in scripture, and therefore, it is not proper biblical Hebrew. It also resembles the word "aninut," which refers to mourning -- certainly not something that one wishes to invoke. Nevertheless, those with the custom to specifically use the “anu” formula may do so.
One who accidentally recited modim d’rabanan during the silent shemoneh esrei is not required to repeat the shemoneh esrei, as the modim d’rabanan is acceptable, b’dieved, for the silent shemoneh esrei, as well. However, if one realizes that one recited the wrong modim before moving on to the next section of the shemoneh esrei, one should recite the proper modim and then continue with one’s shemoneh esrei. Similarly, one who accidentally recited the "regular" modim during the chazarat hashatz is not required to go back and recite the modim d’rabanan, either. Nevertheless, if most of the congregation is still in the midst of reciting the modim d'rabanan one may recite it along with them. There is an opinion that in such a situation, one should begin one’s modim d’rabanan from the words "elohei chol basar" and not from the very beginning.
One should be especially careful to bow as required when reciting modim. The Talmud teaches that one who isn't careful to properly bow at modim will be punished for it. There are a number of different customs on how one should bow when reciting modim d’rabanan. The most widespread practice is to bend the head and upper body at the start of modim and then straighten up when saying "Hashem." Some have the custom to bend their knees, as well, though this is not too widespread. There are also those who merely bow their head at modim. Some also bow at the conclusion of modim d’rabanan and some even bow for the entire modim d’rabanan. Whatever one's custom, one should stand when reciting modim d’rabanan and face east (Jerusalem) when doing so, at least when bowing. One should pause briefly between responding "amen" to the chazzan’s blessing of "hamachazir shechinato l'tzion" and beginning the modim d’rabanan.
One is permitted to recite modim d’rabanan even if one is in the middle of pesukei d'zimra. This is true even if one is in the middle of a paragraph, and even in the middle of a sentence, if necessary. One also joins in with modim d’rabanan if one is in the middle of the birchot kriat shema. In such a situation, however, one only recites the words “modim anachnu lach” and nothing more. These three words may be recited at any time in the birchot kriat shema though it is preferable to pace oneself to ensure that one will be in between paragraphs when it comes time to recite them. One who hears other essential prayers, such as kaddish or barchu, while reciting modim d’rabanan is permitted to make the appropriate responses. There is some discussion whether one who hears a congregation reciting modim d’rabanan is required (or even permitted) to recite it along with them. There is an opinion that one who prays alone should recite the modim d’rabanan as a voluntary prayer at the conclusion of his prayers.
It is interesting to note that when it comes to every other component of the chazarat hashatz, it suffices to simply answer "amen" to the blessings of the shaliach tzibbur. However, as the Abudraham explains, when it comes to modim -- thanking God for the many blessings that He gives us in life -- simply answering amen to the chazzan’s blessing does not suffice. Rather, one must personally thank God oneself. This is why everyone in the congregation is required to recite modim d'rabanan on their own and not merely answer “amen” to the chazzan’s recitation of modim.
 Mishna Berura 101:3.
 Based on Yerushalmi, Berachot 1:5.
 Mishna Berura 127:3.
 Beit Yosef, OC 127.
 Sota 40a.
 Rambam, Hilchot Tefilla 9:4; OC 127:1; Gra, OC 127:2. See also Yerushalmi Sota 7:6 for additional versions of the prayer.
 Tosfot, Sota 40a; Tur, OC 127.
 Rif, Rashba to Berachot 34; Rambam, Hilchot Berachot 9:4.
 OC 127:1; Mishna Berura 127:2.
 Be'er Heitev, OC 187:1; Bishvilei Haminhag 2 p.50.
 Be'er Moshe 4:15; Az Nidberu 8:49.
 Mishnat Yosef 6:42 cited in Avnei Derech 1:20.
 Kaf Hachaim (Palagi) 15:37; Mishna Berura 121:2.
 OC 127:10; Mishna Berura 113:12, 127:2; Kaf Hachaim, OC 127:10.
 Kaf Hachaim, OC 113:21; Kitzur Shulchan Aruch 18:11; Aruch Hashulchan, OC 113:7.
 Bach, OC 127; Ben Ish Chai, Teruma 15; Mishna Berura 127:2; Aruch Hashulchan, OC 127:2.
 OC 127:1; Shulchan Aruch Harav, OC 127:1, Rivevot Ephraim 7:26:2; Sefer Kushiot 224.
 Rema, OC 127:1; Kaf Hachaim, OC 127:10.
 Rema, OC 94:5; Rivevot Ephraim 5:69; Yechave Daat 5:11; Leket Yosher p. 27.
 Magen Avraham 223:2; Tehilla L’david 90:1; Halichot Shlomo 9:11.
 Mishna Berura 124:25.
 Mishna Berura 51:8; Minchat Yitzchak 9:8.
 OC 66:3; Mishna Berura 66:20.
 Salmat Chaim 135 cited in Piskei Teshuvot 127:1. See also Biur Halacha 109 who disagrees.
 Rivevot Ephraim 1:91:2.
 See Avnei Derech 1:20.
 Abudraham Hashalem p. 115; Elya Rabba 127:1. See also Rivevot Ephraim 6:51:2.