Aṣṭavakra is the son of sage Kahoḍa. Maharṣi Uddālaka had a disciple called Kahoḍa. Pleased by his service, Uddālaka trained him in Veda and other scriptures, and after his lessons were over, got him married to his daughter, Sujātā.

In Mahābhārata it is described that Aṣṭāvakra learned Veda, while being in his mother̍s womb, listening to his father.

Once at night, when Kahoḍa was chanting Veda, the baby from the womb spoke out– “It was by your grace that I have been able to study Veda with all its aṅga(s), and from that learning, now it seems to me that your reading is not proper.” Thus denounced by the baby in the womb, Kahoḍa felt very insulted, and cursed him– “Since you, being in the womb, are speaking ill of me, you will be born with a body crooked at eight parts. Cursed by his father, the child came out with a crooked body, and came to be known as Aṣṭāvakra–
sa vai tathā vakra evābhyajāyad aṣṭāvakraḥ prathito vai maharṣiḥ.

Some time before the birth of Aṣṭāvakra, Sujātā requested her husband to earn some wealth, for the purpose of bringing up the child to be born. Kahoḍa went to the court of king Janaka, with the hope of earning some money. There was a scholar called Vandī, well-versed in logical argument. Vandī challenged Kahoḍa to a contest of discourse. There was a condition, the defeated one would be drowned in water. Kahoḍa was defeated by Vandī, and he was drowned.

Uddālaka, the maternal grandfather of Aṣṭāvakra aked Sujātā not to tell the child anything of this sad incident. Sujātā did not let Aṣṭāvakra know about this. Aṣṭāvakra grew up under the affectionate care of his maternal grandfather, and knew him as his own father. He considered his maternal uncle Śvetaketu, to be his brother. Aṣṭāvakra and Śvetaketu were two of the greatest Veda-learned sages in that age.

One day, the twelve-year old Aṣṭāvakra was sitting in the lap of his maternal uncle Uddālaka, suddenly his maternal uncle Śvetaketu came and dragged him by the hand, saying, “This is not your father̍s lap”. Hearing this, the boy Aṣṭāvakra went, weeping, to his mother, and asked, “Where is my father?” Then Sujātā told him in details about the yajña of king Janaka, and the discouse-expert called Vandī. Hearing all this, sage Aṣṭāvakra, along with his maternal uncle Śvetaketu, reached the yajña-place of king Janaka.

The gatemen of Janaka stopped the boy-Brāhmaṇa. Aṣṭāvakra, being angry, said that the way should be clear for brāhmaṇa, king, women and blind persons, before anybody else. Among them, the brāhmaṇa should come first. The knowledge and logical demands of a twelve-year old boy reached king Janaka.

But the gatemen and king Janaka himself were so charmed by the scholarship of Vandī, that they did not allow the boy-bhāhmaṇa to enter the court. After much arguments, Aṣṭāvakra said, “I have heard that Vandī defeat old scholars only to drown them. So I have come to defeat him in logical argument. But king Janaka, considering the ultimate condition of the boy-brahmaṇa, did not wish him to face a scholar like Vandī. He tried to dissuade him, but Aṣṭāvakra remained determined. Janaka himself started asking him very difficult questions, so that Aṣṭāvakra got afraid and change his discision. But the boy-Aṣṭāvakra answered all the questions of King Janaka. Moved by his knowledge, Janaka allowed him to enter. The argument started between Vandī and Aṣṭāvakra, and Vandī was defeated. Then Aṣṭāvakra said, “This Vandī has drowned the defeated brāhmaṇa(s), so let him be drowned as well.” Vandī said, “It is not possible to drown me, because I am the son of Varuṇa. And the Brāhmaṇa(s) whom I drowned, were not dead either. When King Janaka started the yajña, my father, god Varuṇa also started a yajña to be continued for twelve years. Those brāhmaṇa(s) have gone to attend that yajña, and they will come back in time. Kahoḍa and the other Brāhmaṇ(s) came back from the yajña of Varuṇa in due time. King Janaka honoured Aṣṭāvakra.

Kahoḍa was moved by the virtues and knowledge of his son. One day, he asked Aṣṭāvakra to go into the river flowing by the side of his hermitage. The moment Aṣṭāvakra took a dip, his crooked body became straight and normal. For this reason, the river is known as Samaṅgā. This legend suggests the glory of the river. In fact, it appears that Aṣṭāvakra remained crooked in limbs.

In his youth, Aṣṭāvakra got charmed by the beauty of Suprabhā, daughter of sage Vadānya. He expressed his wish to sage Vadānya, who said, “I shall get my daughter married to you, but you have to go to the north before that. There, crossing the mountain Himālaya, and Alakāpurī of Kuvera, lies the abode of Mahādeva. In further north, there is a blue forest, where resides an old lady ascetic. After visiting her and paying homage to her, you come back and then you can marry my daughter.

Hearing this, Aṣṭāvakra set out for the north. Crossing Himālaya, he reached Alakāpurī ruled by Kuvera. Kuvera welcomed the great sage Aṣṭāvakra. In his honour, distinguished Apsarā(s) presented their singing and dancing in the court of Kuvera. Aṣṭāvakra spend one year in that place. Then, he again started his journey towards further north. Crossing the mountains Himālaya, Kailāśa, and Mandara, he found the river Mandākinī , full of mandara flowers, and a beautiful palace by the riverside. Coming to the gate of the palace, Aṣṭṭavakra said, “I have come as a guest”. Hearing this, seven beautiful ladies came out of the palace. Seeing their celestial beauty, Aṣṭavakra was initially charmed, but gradually he controlled his mind. He entered the palace with those ladies, and found an old lady, very much withered, but decked with highly expensive clothes and ornaments, sitting on a bed. Sometimes she assumed the shape of a young girl, sometimes in her old form, she stayed always with Aṣṭāvakra, served him and tried to seduce him by several means. But Aṣṭāvakra remained controlled regarding an unknown woman. This old lady was the embodied form of the North-goddess. Seeing Aṣṭāvakra̍s self-control, she was extremely pleased, and blessed him to enjoy a happy married life and have a son. Paying his respects to the old lady, Aṣṭāvakra came back to sage Vadānya. Finding an honest and virtuous groom like Aṣṭāvakra, Vadānya became very glad, and he gave her daughter in marriage to Aṣṭāvakra.