Abu Yahya Suhaib bin Sinan (radi Allahu anhu) reported that the Messenger of Allah (sal Allahu alaihi wa sallam) said: “How wonderful is the case of a believer; there is good for him in everything and this applies only to a believer. If prosperity befalls him, he expresses gratitude to Allah and that is good for him; and if adversity befalls him, he endures it patiently and that is good for him.” [Sahih Muslim]
For a Muslim there is reward (hasanaat), and thus eternal good (khair), in every circumstance. Since Allah (subhana wa ta’ala) is responsible for all the good that comes to us we thank and praise Him by saying and feeling “Alhamdulillah” in all circumstances.
There was once a courtier of a king who would always say, “Alhamdulillah.” One day the king’s hand got cut. The courtier exclaimed, “Alhamdulillah.” The king got very upset at this and had the courtier thrown into prison. The courtier again said “Alhamdulillah” on being put in jail.
Some time later the king went on a hunt. As he was sleeping under a tree a lion came to attack him. But on smelling the blood and flesh from the king’s cut hand he left him alone considering him to be already dead. When the king realized how his cut hand had saved him he thought of his courtier. He had him recalled from prison and asked him, “I understand your wisdom in proclaiming ‘Alhamdulillah’ when my hand got cut, but why did you say ‘Alhamdulillah’ when you were thrown into prison?” The courtier replied, “If I hadn’t been put in jail I would have accompanied you on your hunt. The lion would have left you alone but gone after me.”
Thus, a Muslim always says “Alhamdulillah.” When he is happy and feels grateful to Allah (subhana wa ta’la) he is rewarded by Allah. And when he is sad but patient with Allah’s Decree, he is again rewarded by Him (subhana wa ta’ala).