Intentionally speaking during the salah, if it is not beneficial to the salah, invalidates the salah.
Zaid ibn Arqam relates: “We used to talk while we were in salah and a person would speak to the person next to him until the verse was revealed: ‘And stand before Allah in devout obedience’ and we were then commanded to observe silence during the salah.” This is related by the group.
Ibn Mas’ud reports: “We used to greet the Messenger of Allah while he was in salah and he would respond to our greeting. When we returned from Abyssinia, we greeted him [during prayer] but he did not respond to our salutation. We said to him: ‘O Messenger of Allah, we used to greet you while you were in salah and you used to respond to us!’ He then said: ‘Prayer demands one’s complete attention.'” This is related by al-Bukhari and Muslim.
If one is ignorant of this ruling or speaks due to the fact that he has forgotten this ruling, his salah will still be valid
Mu’awiyyah ibn alHakam said: “I was praying behind the Messenger of Allah and someone in the congregation sneezed. I said [to him]: ‘May Allah have mercy upon you.’ The people then stared at me, showing their disapproval of my act. I said: ‘Woe to me, why do you stare at me so?’ They started to strike their hands on their thighs and when I saw that they wanted me to become silent, I was angered but said nothing. When the Messenger of Allah finished the prayer – and may my father and mother be ransomed for him, I found no teacher better than him either before or after him – he did not scold, beat, or revile me but he simply said: ‘Talking to others is not seemly during the salah, for the salah is for glorifying Allah, extolling His Greatness, and reciting the Qur’an.'” This is related by Ahmad, Muslim, Abu Dawud, and an-Nasa’i. Mu’awiyyah ibn al-Hakam spoke out of ignorance of this ruling and the Prophet sallallahu alehi wasallam did not order him to repeat his salah.
Talking [if it is a reminder as to the incompleteness of the salah], does not nullify the salah as can be seen in the following hadith. Abu Hurairah says: “The Messenger of Allah led us in either the noon or after-noon prayers and he made the taslim after praying just two rak’at. Zhul Yadain said to the Prophet: ‘O Messenger of Allah, has the salah been shortened or have you forgotten [part of it]?’ The Prophet sallallahu alehi wassalam said: ‘It has not been shortened, nor did I forget any part of it.” He said: ‘Yes, O Messenger of Allah, you did forget.’ Thereupon the Prophet asked (the people): ‘Is Zhul Yadain correct in what he says?’ The people said: ‘He is correct, you offered only two rak’at.’ Then, the Prophet prayed the two remaining rak’at and made the taslim, said the takbir and performed the sajdah, sat and made the takbir and performed the sajdah again, and finally said the takbir and sat again.” This is related by al-Bukhari and Muslim.
The Maliki school allows talking during the prayer if it is done for any good of the salah as long as it does not become a common practice and (is done) only when saying subhanallah fails to alert the imam to correct his mistake. Al-Auza’i’s comments are: “Whoever intentionally speaks during the salah, seeking some benefit to the salah, does not invalidate his salah.” He said that if a person recites aloud in the ‘asr and someone behind him says: “It is the ‘asr,” (i.e., the recital is not to be aloud) then the latter person would not invalidate his salah.