At the time of his kidnapping Joseph was seventeen.
Genesis 37:2 Joseph, being seventeen years old, was pasturing the flock with his brothers.
After travelling to Egypt, he was sold as a slave to Potiphar, and succeeded in his household. There is no information about how old Joseph was when he was wrongly accused and imprisoned. Two years before he was released from prison Joseph explained the meaning of the dreams of two of the prisoners of Pharaoh. He was thirty years old when he left prison, about thirteen years after his kidnapping.
Genesis 41:46 Joseph was thirty years old when he entered the service of Pharaoh king of Egypt
How long was Joseph is prison? More than two, but less than thirteen years.