Dua when having a bad dream or nightmare
أَعـوذُ بِاللهِ مِنَ الشَّيْـطانِ الرَّجيـم وَمِنْ...
أَعـوذُ بِاللهِ مِنَ الشَّيْـطانِ الرَّجيـم وَمِنْ شَرِّ هَـذِهِ الرُّؤيـا
aAAoothu billahi minash-shaytanir-rajeem wamin sharri hathihir-ru'ya
Translation
I take refuge with Allah from the accursed devil and from the evil of this dream.
When to recite
Recited upon waking from a nightmare. Also: spit lightly to the left three times, turn over to the other side, and do not tell anyone about it. If you do this it will not harm you.
Source / Reference
Muslim 4/1772, Al-Bukhari 9/44