Sahih al-Bukhari, Hadith 7390

Narrated Jabir bin `Abdullah: As-Salami: Allah's Messenger used to teach his companions to perform the prayer of Istikhara for each and every matter just as he used to teach them the Suras from the Qur'an He used to say, "If anyone of you intends to do some thing, he should offer a two rak`at prayer other than the compulsory prayers, and after finishing it, he should say: O Allah! I consult You, for You have all knowledge, and appeal to You to support me with Your Power and ask for Your Bounty, for You are able to do things while I am not, and You know while I do not; and You are the Knower of the Unseen. O Allah If You know It this matter (name your matter) is good for me both at present and in the future, (or in my religion), in my this life and in the Hereafter, then fulfill it for me and make it easy for me, and then bestow Your Blessings on me in that matter. O Allah! If You know that this matter is not good for me in my religion, in my this life and in my coming Hereafter (or at present or in the future), then divert me from it and choose for me what is good wherever it may be, and make me be pleased with it." (See Hadith No. 391, Vol. 8)

حَدَّثَنِي إِبْرَاهِيمُ بْنُ الْمُنْذِرِ، حَدَّثَنَا مَعْنُ بْنُ عِيسَى، حَدَّثَنِي عَبْدُ الرَّحْمَنِ بْنُ أَبِي الْمَوَالِي، قَالَ سَمِعْتُ مُحَمَّدَ بْنَ الْمُنْكَدِرِ، يُحَدِّثُ عَبْدَ اللَّهِ بْنَ الْحَسَنِ يَقُولُ أَخْبَرَنِي جَابِرُ بْنُ عَبْدِ اللَّهِ السَّلَمِيُّ، قَالَ كَانَ رَسُولُ اللَّهِ صلى الله عليه وسلم يُعَلِّمُ أَصْحَابَهُ الاِسْتِخَارَةَ فِي الأُمُورِ كُلِّهَا، كَمَا يُعَلِّمُ السُّورَةَ مِنَ الْقُرْآنِ يَقُولُ ‏ "‏ إِذَا هَمَّ أَحَدُكُمْ بِالأَمْرِ فَلْيَرْكَعْ رَكْعَتَيْنِ مِنْ غَيْرِ الْفَرِيضَةِ ثُمَّ لِيَقُلِ اللَّهُمَّ إِنِّي أَسْتَخِيرُكَ بِعِلْمِكَ، وَأَسْتَقْدِرُكَ بِقُدْرَتِكَ، وَأَسْأَلُكَ مِنْ فَضْلِكَ، فَإِنَّكَ تَقْدِرُ وَلاَ أَقْدِرُ، وَتَعْلَمُ وَلاَ أَعْلَمُ، وَأَنْتَ عَلاَّمُ الْغُيُوبِ، اللَّهُمَّ فَإِنْ كُنْتَ تَعْلَمُ هَذَا الأَمْرَ ـ ثُمَّ تُسَمِّيهِ بِعَيْنِهِ ـ خَيْرًا لِي فِي عَاجِلِ أَمْرِي وَآجِلِهِ ـ قَالَ أَوْ فِي دِينِي وَمَعَاشِي وَعَاقِبَةِ أَمْرِي ـ فَاقْدُرْهُ لِي، وَيَسِّرْهُ لِي، ثُمَّ بَارِكْ لِي فِيهِ، اللَّهُمَّ وَإِنْ كُنْتَ تَعْلَمُ أَنَّهُ شَرٌّ لِي فِي دِينِي وَمَعَاشِي وَعَاقِبَةِ أَمْرِي ـ أَوْ قَالَ فِي عَاجِلِ أَمْرِي وَآجِلِهِ ـ فَاصْرِفْنِي عَنْهُ، وَاقْدُرْ لِيَ الْخَيْرَ حَيْثُ كَانَ، ثُمَّ رَضِّنِي بِهِ ‏" ‏‏.‏

sunnah.com