Praise be to Allah.
It is Sunnah for the one who is praying, if he notices the whisper of the Shaytaan during his prayer, to seek refuge with Allah from him and to turn his head only, then spit dryly to his left three times, because of the report narrated by Muslim (2203) from ‘Uthmaan ibn Abi’l-‘Aas (may Allah be pleased with him), according to which he came to the Prophet (blessings and peace of Allah be upon him) and said: O Messenger of Allaah, the shaytaan interferes between me and my prayer and my recitation, and he makes me confused. The Messenger of Allaah (blessings and peace of Allah be upon him) said: “That is a devil called Khinzab. If you feel that, then seek refuge with Allaah from him and spit dryly to your left three times.” He said: I did that and Allaah took him away from me..
Shaykh Ibn Baaz (may Allah have mercy on him) said:
There is nothing wrong with turning during the prayer to seek refuge with Allah from the accursed Shaytaan when experiencing his whispers. In fact it is mustahabb in the case of urgent need, by turning the head only, because the Prophet (blessings and peace of Allah be upon him) instructed ‘Uthmaan ibn Abi’l-‘Aas al-Thaqafi (may Allah be pleased with him) to do that when he complained to him of what he was experiencing of the whispers of the Shaytaan. He told him to spit dryly to his left three times and to seek refuge with Allah from the Shaytaan. He did that and Allah healed him of that. End quote. Majmoo‘ Fataawa Ibn Baaz, 11/130
Ibn al-Qayyim (may Allah have mercy on him) said:
If a person seeks refuge with Allah from the accursed Shaytaan and spits dryly to his left, that does not matter and does not interrupt his prayer; rather this makes the prayer more complete and more perfect. End quote. Zaad al-Ma‘aad, 3/602
Spitting dryly is not the usual kind of spitting; rather it is blowing with a little saliva.
If a man is praying with the congregation, then he cannot spit to his left in most cases, because that will bother the person who is standing to his left, unless he is the last one on the left of the row.
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said:
Someone may ask: If a man is praying in congregation, how can he spit dryly to his left? The answer is: If he is the last one on the left, he can spit dryly to his left in any place other than the mosque. Otherwise, he may spit dryly to his left into his garment or his ghutrah (head cover) or a handkerchief. If that is not possible, it is sufficient to turn to his left and say: A‘oodhu Billaahi min al-Shaytaan il-Rajeem (I seek refuge with Allah from the accursed Shaytaan). End quote. Fataawa Noor ‘ala al-Darb (12/155)
He also said:
If a person is praying in congregation, what should he do? How can he spit dryly to his left three times? We say: It is sufficient to seek refuge with Allah from the accursed Shaytaan without spitting dryly, so as to avoid bothering people around you. End quote. Fataawa Noor ‘ala al-Darb, 185/45
And Allah knows best.