Once Koshala was a great kingdom and king Sagara was performing Ashwamedha Yagna. He lost the track of his sacrificial horse. He sent his 60 thousand sons to find the horse. They searched horse in every corner of earth & destroyed everything that came in their path. At last they reached to sage Kapila asharam and they saw the horse was tied. They made charges on the sage of stealing the horse. As a result of this offense to sage Kapila, all sixty thousand sons were burned to ashes. King Sagara waiting for his sons then sent his grandson Anshuman. Kapila said to him that only by the presence of sacred river Ganga, all sixty thousand sons will be purified and delivered.
Many kings of the dynasty performed austere penance for getting Ganga but could not bring Ganga on earth.
As time passed, their curse multiplied and it started to even destroy the Koshala kingdom. And then king Bhagirathi spur into action and did penance for 1000 years & pleased Lord Brahma to send Ganga on earth. Now the force of river was so destructive that earth will not be able to hold it. For that Brahma told Bhagirathi to pray to Lord Shiva. After a year of penance Lord Shiva appeared & told Bhagirathi that his wish would be fulfilled. When Ganga was falling from heaven, everybody was so afraid that everything would be destroyed. Ganga came forcefully. As it was going to hit the earth Lord Shiva captured her in his jata (matted hair). Ganga was helpless and was unable to come out of it. At this Bhagirathi prayed Shiva again & Lord Shiva released Ganga.
Ganga now flowed behind Bhagirathi giving liberation to all his ancestors. Before this, Bhagiratha also got her on the way to Varanasi. Varanasi is eternal abode of Shiva. So to pay the homage to the city, Ganga decided to change course and flew northward. The city is east facing and its boundaries lying between Asi & Varuna rivers. The direction of the sacred river Ganga is northward in city. In Indian culture a place where two rivers join is sacred so in Varanasi the numbers are three thus making it even more auspicious.