An-Nawawee – may Allah shower blessings on him – said in his Book, Riyaad as-Saaliheen, Chapter on Asking Allah for Guidance and Consulting People.
Al-Istikharah (as in the Arabic text, rendered as, asking Allah for guidance) is directed to Allah while Al-Mushawarah (in the text, translated as consultation) should be sought with reasonable and pious people. Because man necessarily has defects or deficiencies, and he is created weak; he may be confused regarding a matter and
hesitant about it; what does he do? Let's assume he wants to travel but he doubts whether it is good or bad (for him); or that he intends to buy a car or house or seeks to propose to a man to marry his daughter or similar other things, but he about it. What then should he do? We say he has two paths:
The first path: To ask the Lord of all that exists – the Mighty and Sublime –, Who knows the past and the future and how they will happen.
The second path: After that, he should consult the people of reason, piety and trust.
The author – may Allah shower blessings on him – buttressed consulting people with two verses from Allah's Book; and they are:
“And consult them in the affairs.”
This expression was directed to the Prophet ﷺ. Allah – the Exalted - said to him:
“So pass over (their faults) and ask (Allah) forgiveness for them: and consult them in the affairs. Then when you have taken a decision, put your trust in Allah.” (Aal-Imraan: 159)
The Prophet ﷺ who was the best person in his thoughts and most correct of them would also seek the advice of his companions in some matters that prove difficult. Likewise the caliphs after him, they would consult the upright and reasonable persons.
These two conditions are unavoidable regarding the person you wish to consult: that he is learned and experienced regarding the matter, critical and not hasty, and that he is upright upon his religion. Because the person who is not upright in his religion cannot be trusted even if he were intelligent and experienced in the matters, there is no gain consulting him. He does not deserve to be among those who are consulted because being not upright in his religion, he could be
treacherous – and the refuge is with Allah - and direct you that which is harmful or something which is not beneficial and then cause evil and destruction to an extent Allah alone knows.
Let us suppose he of the people of sin, shamelessness and evil, it is not permissible to seek his advice because that will put you in to a pit of destruction!
Similarly, if he were upright in his religion, intelligent and trustworthy but indifferent and inexperienced or hasty and not insightful, do not be eager to consult such a person because if he is negligent and inexperienced, he might approach them superficially, not paying attention to their antecedents. If he is hasty as well, his impatience could make him direct you to something lacking in any benefit. So, the individual must necessarily be a person of insight, reason and uprightness in his religion. Allah, the Mighty and Sublime said,
“And who (conduct) their affairs by mutual consultation”
(Ash-Shoorah: 38)
That is, their affairs – collective, involving all -, for example, the Jihad; it is decided by consultation among them. When the ruler wants to – for instance -, wage a Military campaign or do something involving the generality of the Muslims, then he should consult them. However, how does he consult them? Consultation occurs when he has a matter over which he is hesitant; he will gather those he considers qualified to be consulted considering their intellect, piety and their wise counsels.
As for asking Allah the Mighty and Sublime for guidance, such is only directed to Allah. The individual would supplicate to Allah – the Lord of all that exists - after deciding on a matter whose result or consequence he would not know. Al-Istikharah (asking Allah for guidance on a matter) essentially means, seeking the best of two affairs.
The Prophet ﷺ had pointed to that; that the individual should observed two units of non-obligatory Prayer at other than the times in which observing the Prayers are prohibited except if the matter involves urgency before the end of prohibited time; then, the Prayer could be observed even during mentioned the prohibited times.
However, if the matter is not pressing, then it is not allowed to observe the Prayer for Asking Allah for guidance within the prohibited period: after the 'Asr Prayer, do not give the Istikharah, likewise after the Fajr Prayer till the sun rises the height of a spear. Similarly, the supplication should not be made while the sun descends its horizon till it fully leaves except when the matter compels immediate action; then the two-unit non-obligatory Prayer could be observed. After ending it, he should then say, "Allahumma inni astakheeruka bi ilmika, wa astaqdiruka bi Qudratika, wa as'alukamin fadlika Al-Azeemi, fa innaka taqdiru wa la aqdiru, wa ta'lamu wa la a'lamu, wa Anta Allamul-Ghuyubi, Allahumma in kunta ta'alamu, anna hadha Al-amra' (Meaning: O Allah I seek the counsel of Your knowledge and I seek the help of Your Omnipotence and I beseech Your Magnificent Grace, surely You are Capable and I am not. You know and I know not and You are the Knower of the unseen. O Allah, surely You know, so if this matter) - then he mentions it; for example, we assume he wants to request to marry from a people and become an in-law to them: Allahumma in kunta ta'lamu anna zawaaji hadhihi Al-Bint - (O Allah You surely know, so if this my marrying of this lady) khairan li fee deeni wa ma'aashi wa aaqibati amri - (or say) Aajili amri wa aajilihi - that is, either you said the first or the second statement, 'faqdirhu li wa yassirhu li, thumma baarik li fihi, wa in kunta ta'lamu anna hadha Al-amra sharrun li fee deeni, wa ma'aashi wa aaqibati amri - (or say) - Aajili amri wa aajilihi. Fasrifhu anni wasrifni anhu waqdur li Al-Khayra haithu kaana, thumma ardini bihi (is good for me in my religion and in my life and for my welfare in the life to come (or say) in the present and in the future (life), then ordain it for me and make it easy for me then bless me in it. And if this matter is evil for me in
my religion and in my life and for my welfare in the life to come (or say) in the present (life) and in the future (life) then distance it from me and distance me from it and ordain for me what is good wherever it be found and help me to be content therewith) and that is the end.
Thereafter, if his heart tends to one of the two options, that is, to continue or to desist, this is what is excepted; he should choose what his heart tends to. But if his heart does not lean to any of the two, then he should repeat the Istikharah a second and third time.
Then consulting people; if nothing becomes weighty to him after the Istikhaarah, then he should consult the people good opinions and uprightness; and whatever they advise him to do is best - by Allah's leave. Allah may not make his heart lean towards a particular option till he consults the peoples and afterwards Allah makes his mind firm upon a decision.
The scholars hold differently whether the consultation should come first or the Prayer?
The correct view, anyway, is that the Prayer for guidance should come first based on the Prophet's statement that, "When anyone of you decides a matter, he should observe two units of Prayer..." to the end. So you should start with the Prayer and then after repeating it thrice, and nothing comes firm in your mind, then consult. And then, whatever you are guided to may be what Allah has chosen for you; take it. We hold that: He should give the Prayer for guidance thrice, because from the general practice of the Prophet ﷺ, was that when he supplicated, he did so three times, and Istikhaarah is a kind of supplication as well.
The best of the two options may not be clear to the individual from the onset, and it may from the very beginning, or the second time or still, only at the third time. And if it still does not become clear, then you should consult.
Allah alone grants success.