The Messenger of Allah ﷺ used to teach us how to seek guidance through istikhara in all matters, just as he taught us a surah from the Quran. He would say, "When one of you is concerned about a matter, let him pray two units of prayer other than the obligatory prayer, then say,'O Allah, I seek Your guidance through Your knowledge, and I seek Your strength through Your power, and I ask You from Your immense bounty. For You have power and I have none, and You know and I do not, and You are the Knower of all unseen things.O Allah, if You know that this matter is good for me in my religion, my livelihood, and the outcome of my affair,' or he said, 'in the immediate and distant future of my affair, then make it easy for me and bless me in it. And if You know that this matter is bad for me in my religion, my livelihood, and the outcome of my affair,' or he said, 'in the immediate and distant future of my affair, then turn it away from me and turn me away from it, and decree for me what is good wherever it may be, then make me content with it.'"He said, "And he should name his need."
حدثنا قتيبة حدثنا عبد الرحمن بن أبي الموالي عن محمد بن المنكدر
كان رسول الله ﷺ يعلمنا الاستخارة في الأمور كلها كما يعلمنا السورة من القرآن يقول إذا هم أحدكم بالأمر فليركع ركعتين من غير الفريضة ثم ليقل اللهم إني أستخيرك بعلمك وأستقدرك بقدرتك وأسألك من فضلك العظيم فإنك تقدر ولا أقدر وتعلم ولا أعلم وأنت علام الغيوب اللهم إن كنت تعلم أن هذا الأمر خير لي في ديني ومعيشتي وعاقبة أمري أو قال في عاجل أمري وآجله فيسره لي ثم بارك لي فيه وإن كنت تعلم أن هذا الأمر شر لي في ديني ومعيشتي وعاقبة أمري أو قال في عاجل أمري وآجله فاصرفه عني واصرفني عنه واقدر لي الخير حيث كان ثم أرضني به قال ويسمي حاجته
Bukhari also recorded it in tahajjud, chapter on what has been reported regarding voluntary prayers being offered two by two, hadith no. 1162, from Qutayba, with the same chain.On this subject there are also narrations from Abdullah bin Masud [Tabarani in Al-Kabir, 10/95, hadith no. 10012, its chain being extremely daif] and Abu Ayub [Ahmad, 5/423, and Ibn Khuzayma, hadith no. 1220, and Ibn Hibban, 685, and Al-Mustadrak of Hakim, 2/165, 314].