Exile of Pandavas in the forests was a result of their loss of the game of dice. As per the rule which was set before the Pandavas had to go for an exile of twelve years and the thirteenth year should be spend unrecognized. In case they were recognized in the thirteenth year then they would have to go for another twelve years of exile. Thus, when Yudhisthir lost in the game of dice, he along with his brothers and Draupadi went to the forest leaving his kingdom, his wealth and other belongings.
Yudhisthir, after being exiled for twelve year along with his brothers and his wife, and foresaw that at some future time the differences between their cousins and themselves would have to be decided by the fortunes of war. He also remembered that Duryodhana was in actual possession of the throne and treasury, and that all the friends of their youth whose prowess on the field were known all over the world, were devoted to Duryodhana. Dronacharya and his pupils, above all Karna, would fight and die, if need be, not for the Pandavas, but for Duryodhana, son of Dhritarashtra, the reigning king. At that time there came a holy man and he almost read what was going on then in the mind of Yudhisthir. He told the eldest Pandava prince that there was no one in the world who could defeat his brother Arjuna if he goes to the mountains to get the vision of the Great God and it was destined that all his enemies would be killed by him. Thus, Arjuna went to the mountains, and fasted and prayed to the great God and at last was blessed with all the divine weapons and returned to meet his brothers.
Once the twelve years of exile was over, the Pandavas decided to move to the capital city of the King Virata and disguised themselves in order to be unidentified by all. The five brothers disguised relating according to their personality with Yudhisthira assuming the name as Kankanbhata and served the king as his adviser and priest. Bhima became the head cook in the royal kitchen of the king and Arjuna was destined to serve a year as a eunuch as per the curse of Urvasi and thus he became Brihnnala and taught dance and music to the princess Uttara. Nakula was named Granthic and he became the caretaker and guard to the horse stable and Sahadeva named himself as Tantipal. The queen Draupadi disguised herself as Sairandhri and became the chief maid-servant to the queen. Thus, the thirteenth year of unrecognized exile passed well and the Pandavas once more, by their prowess in battle, had revealed themselves to their friends.