Muhammad bin al-Munkadir narrates from Sayyiduna Jabir (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) used to teach us istikharah (seeking Allah's choice) in matters just as he taught us the surahs of the Qur'an. He (peace and blessings be upon him) would say: "When one of you intends to do something, let him offer two rak'ahs, other than the obligatory prayer, then let him recite this supplication:
'Allahumma inni astakhiruka bi-'ilmika wa astaqdiruka bi-qudratika, wa as'aluka min fadlika al-'azim, fa-innaka ta'lamu wa la a'lamu, wa taqdiru wa la aqdiru, wa anta 'allam al-ghuyub. Allahumma fa-in kunta ta'lamu hadha al-amra (he names the specific matter he intends) khayran li fi dini wa ma'ashi wa ma'adi wa 'aqibati amri, fa-uqdurhu li wa yassirhu li wa barik li fihi. Allahumma wa in kunta ta'lamuhu sharran li mithla al-awwal, fa-srifhu 'anni wa-srifni 'anhu, wa-uqdur liya al-khayra haythu kana, thumma raddini bihi. Aw qala: fi 'ajili amri wa ajilihi'
(O Allah! I seek good from You through Your knowledge, I seek ability through Your power, and I ask of Your immense bounty. You know everything while I know nothing. Indeed You are the source of power and I have no power. You alone are the Knower of the unseen. O Allah! If in Your sight this matter (here he names the intended matter) is better for me with regard to my religion, my worldly life and the outcome of my Hereafter, then grant me the ability to do it, make it easy for me and bless me in it. O Allah! If in Your sight it is not good for me, then turn it away from me and turn me away from it, and grant me the ability and resolve to attain good wherever it may be. Then make me pleased with it. Or he said: in matters that come sooner or later.)"
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4921