Two important men in Egypt have offended Pharaoh. We don't know what they have done, but it is enough to land them in jail. Perhaps they served a less-than-stellar meal to the Pharaoh. Who knows? They were probably being held in jail, awaiting their trial and sentencing.
Each of these gentlemen has a dream in prison.
It is no coincidence that they each have their dream on the same night, and that the dreams are similar to one another in theme. Both dreams include the number three. And it is no coincidence that Joseph is in charge of the prisoners and he notices their countenance the morning after their dreams.
Look at verse 8
And they said to him, “We each have had a dream, and there is no interpreter of it.”
So Joseph said to them, “Do not interpretations belong to God? Tell them to me, please.”
And Joseph said to him, “This is the interpretation of it: The three branches are three days. Now within three days Pharaoh will lift up your head and restore you to your place, and you will put Pharaoh’s cup in his hand according to the former manner, when you were his butler.
But remember me when it is well with you, and please show kindness to me; make mention of me to Pharaoh, and get me out of this house. For indeed I was stolen away from the land of the Hebrews; and also I have done nothing here that they should put me into the dungeon.”
“I also was in my dream, and there were three white baskets on my head. In the uppermost basket were all kinds of baked goods for Pharaoh, and the birds ate them out of the basket on my head.”
Joseph's reply was:
So Joseph answered and said, “This is the interpretation of it: The three baskets are three days. Within three days Pharaoh will lift off your head from you and hang you on a tree; and the birds will eat your flesh from you.”
Gulp. I'm guessing that this is not what the baker wanted to hear. There was a form of capital punishment used at this time in Egypt which involved beheading, and the headless body was left hanging on a tree for birds to peck at until it was devoured.