A Commentary, Critical, Practical, and Explanatory on the Old and New Testaments, by Robert Jamieson, A.R. Fausset and David Brown  at sacred-texts.com
gen 40:1TWO STATE PRISONERS. (Gen 40:1-8)
the butler--not only the cup-bearer, but overseer of the royal vineyards, as well as the cellars; having, probably, some hundreds of people under him.
baker--or cook, had the superintendence of every thing relating to the providing and preparing of meats for the royal table. Both officers, especially the former, were, in ancient Egypt, always persons of great rank and importance; and from the confidential nature of their employment, as well as their access to the royal presence, they were generally the highest nobles or princes of the blood.
gen 40:3Pharaoh put them in ward, &c.--Whatever was their crime, they were committed, until their case could be investigated, to the custody of the captain of the guard, that is, Potiphar, in an outer part of whose house the royal prison was situated.
gen 40:4The captain of the guard charged Joseph with them--not the keeper, though he was most favorably disposed; but Potiphar himself, who, it would seem, was by this time satisfied of the perfect innocence of the young Hebrew; though, probably, to prevent the exposure of his family, he deemed it prudent to detain him in confinement (see Psa 37:5).
They continued a season in ward--literally, "days," how long, is uncertain; but as they were called to account on the king's birthday, it has been supposed that their offense had been committed on the preceding anniversary [CALVIN].
gen 40:5they dreamed a dream--Joseph, influenced by the spirit of true religion, could feel for others (Ecc 4:1; Rom 12:15; Phi 2:4). Observing them one day extremely depressed, he inquired the cause of their melancholy; and being informed it was owing to a dream they had respectively dreamed during the previous night, after piously directing them to God (Dan 2:30; Isa 26:10), he volunteered to aid them, through the divine help, in discovering the import of their vision. The influence of Providence must be seen in the remarkable fact of both officers dreaming such dreams in one night. He moves the spirits of men.
gen 40:9THE BUTLER'S DREAM. (Gen 40:9-15)
In my dream, behold, a vine was before me--The visionary scene described seems to represent the king as taking exercise and attended by his butler, who gave him a cooling draught. On all occasions, the kings of ancient Egypt were required to practice temperance in the use of wine [WILKINSON]; but in this scene, it is a prepared beverage he is drinking, probably the sherbet of the present day. Everything was done in the king's presence--the cup was washed, the juice of the grapes pressed into it; and it was then handed to him--not grasped; but lightly resting on the tips of the fingers.
gen 40:12Joseph said, . . . This is the interpretation--Speaking as an inspired interpreter, he told the butler that within three days he would be restored to all the honors and privileges of his office; and while making that joyful announcement, he earnestly bespoke the officer's influence for his own liberation. Nothing has hitherto met us in the record indicative of Joseph's feelings; but this earnest appeal reveals a sadness and impatient longing for release, which not all his piety and faith in God could dispel.
gen 40:16THE BAKER'S DREAM. (Gen 40:16-23)
I had three white baskets--The circumstances mentioned exactly describe his duties, which, notwithstanding numerous assistants, he performed with his own hands.
white--literally, "full of holes"; that is, wicker baskets. The meats were carried to table upon the head in three baskets, one piled upon the other; and in the uppermost, the bakemeats. And in crossing the open courts, from the kitchen to the dining rooms, the removal of the viands by a vulture, eagle, ibis, or other rapacious bird, was a frequent occurrence in the palaces of Egypt, as it is an everyday incident in the hot countries of the East still. The risk from these carnivorous birds was the greater in the cities of Egypt, where being held sacred, it was unlawful to destroy them; and they swarmed in such numbers as to be a great annoyance to the people.
gen 40:18Joseph answered and said, This is the interpretation--The purport was that in three days his execution should be ordered. The language of Joseph describes minutely one form of capital punishment that prevailed in Egypt; namely, that the criminal was decapitated and then his headless body gibbeted on a tree by the highway till it was gradually devoured by the ravenous birds.
gen 40:20it came to pass the third day, which was Pharaoh's birthday--This was a holiday season, celebrated at court with great magnificence and honored by a free pardon to prisoners. Accordingly, the issue happened to the butler and baker, as Joseph had foretold. Doubtless, he felt it painful to communicate such dismal tidings to the baker; but he could not help announcing what God had revealed to him; and it was for the honor of the true God that he should speak plainly.
gen 40:23yet did not the chief butler remember Joseph--This was human nature. How prone are men to forget and neglect in prosperity, those who have been their companions in adversity (Amo 6:6)! But although reflecting no credit on the butler, it was wisely ordered in the providence of God that he should forget him. The divine purposes required that Joseph should obtain his deliverance in another way, and by other means.