Genesis 40

1 We do not know what the offenses were, but they apparently deserved imprisonment and death.
3 The captain of the guard was apparently responsible for the royal prison, but the warden ran it (although he had given that responsibility to Joseph). It is possible that Potiphar was still the captain of the guard, but since his name is not given here, he may have moved on to another position.
4 Joseph met everyone who was thrown into prison. Joseph in charge of meeting all their needs, so he was a servant to them all.
5 Dreams were considered very important. Several times in the Bible God speaks to people in dreams -- both to the godly and ungodly. Overall, very few dreams are messages from God. However, these men had profound dreams that they somehow knew that meant something important and needed interpretation. While in Pharaoh's court, they would have had easy access to pagan astrologers who would have given worldly interpretations, but in prison, they felt they had no hope of understanding their dreams.

Joseph knew that the only God could grant special dreams and their interpretations. Joseph's relationship with God was so close that Joseph felt confident that God would reveal the meaning of the dreams to him.

6 Joseph really cares about his prison companions. Of course, prisoners were sad to be confined, but on this particular morning, they appeared even more so. Joseph wanted to help if he could.
11 The cupbearer had the privilege of serving the king directly (see also Neh 1:11). The cupbearer was also required to taste the drink before the king did to make sure that it was not poisoned. The cupbearer had to be highly trustworthy.
13 The cupbearer was to be exonerated.
14 Joseph was a good servant in prison, but did not like being there. We should be good workers even if we are in grim conditions. However, it is not wrong for one to want to improve his position or move out of an undesirable situation. Here Joseph wants the cupbearer to be a contact for him to Pharaoh.
15 This is the first time we hear Joseph claim innocence in the matter if Potiphar's wife. Perhaps the cupbearer, also proved to be innocent, would be sympathetic to Joseph and seek his release.
16 Unfortunately for the cook, Joseph was not the "fortune cookie" man. Not all messages from God are pleasant, for God punishes the wicked just as He rescues those who depend on Him.
19 The cook would be "hanged from a tree" with a rope. It is not until Roman times that this phrase would indicate crucifixion. Being hung on a tree was considered the ultimate curse in punishment (Deu 21:23). The punishment was humiliating for both the criminal and the family since it was done in public. God would later forbid a body to be hung overnight. It was to be given a proper burial since it still bore His image (not to mention that the decaying body would become disease infested, stinky, and unsightly). However, Pharaoh would leave the rotting corpse up in the tree and scavengers would eat it. There would be no body to bury.

This is the first time capital punishment is mentioned. We are not told what the offense was. Presumably, Pharaoh had discovered that the cook was plotting against him. During his birthday party, Pharaoh would display his power and authority by exonerating the butler and executing the cook.

20 Some have said that only pagans celebrated birthdays, but that this is probably not entirely true. It is obvious from reading the various genealogies that records were kept of people's ages. Even Jesus had an age (Luke 3:23). Now it might be true that pagans put more emphasis on birthdays by throwing big parties -- at least the rich did (the only other birthday party mentioned in the Bible is in Mat 14:6). It is also true that our physical birth is of little value if we are not born again spiritually (John 3:3-7). The body we live in will die, but the spirit will live forever (1 Pet 1:23).
21 Just as Joseph had said, so the events took place.
23 Just three days before, the cupbearer's entire hope was in what Joseph said. He was so overjoyed at being restored that his memory faded quickly.

We are often the same way. God has given us so many things, not the least of which is eternal salvation, but we quickly forget, and are slow to tell others.

However, Joseph's release would eventually happen. God did not want Joseph let out of prison right away, but He was waiting for the right time.