Ancient history of Nepal
The earliest inhabitants of modern Nepal and adjoining areas are believed to be people from the Indus Valley civilization. By 4000 BCE, the Tibeto-Burmese people had reached Nepal either directly across the Himalayas from Tibet or via Myanmar and north-east India or both. By the late Vedic period, Nepal was being mentioned in various Hindu texts, such as the late Vedic Atharvaveda Pariśiṣṭa and in the post-Vedic Atharvashirsha Upanishad. The Gopal Bansa was the oldest dynasty to be mentioned in various texts as the earliest rulers of the central Himalayan kingdom known by the name 'Nepal'. The Gopalas were followed by Kiratas who ruled for over 16 centuries by some accounts. According to the Mahabharata, the then Kirata king went to take part in the Battle of Kurukshetra. In the south-eastern region, Janakpurdham was the capital of the prosperous kingdom of Videha or Mithila, that extended down to the Ganges, and home to King Janaka and his daughter, Sita. Around 600 BCE, small kingdoms and confederations of clans arose in the southern regions of Nepal. From one of these, the Shakya polity, arose a prince who later renounced his status to lead an ascetic life, founded Buddhism, and came to be known as Gautama Buddha (traditionally dated 563–483 BCE). Nepal came to be established as a land of spirituality and refuge in the intervening centuries, played an important role in transmitting Buddhism to East Asia via Tibet, and helped preserve Hindu and Buddhist manuscripts. By 250 BCE, the southern regions had come under the influence of the Maurya Empire. Emperor Ashoka made a pilgrimage to Lumbini and erected a pillar at Buddha's birthplace, the inscriptions on which mark the starting point for properly recorded history of Nepal. Ashoka also visited the Kathmandu valley and built monuments commemorating Gautama Buddha's visit there. By the 4th century AD, much of Nepal was under the influence of the Gupta Empire. In the Kathmandu valley, the Kiratas were pushed eastward by the Licchavis, and the Licchavi dynasty came into power  400 AD. The Lichchhavis built monuments and left a series of inscriptions; Nepal's history of the period is pieced together almost entirely from them. The Licchavi dynasty went into decline in the late 8th century and was followed by a Thakuri rule. Thakuri kings ruled over the country up to the middle of the 11th century AD; not much is known of this period that is often called the dark period. Prehistory 
Prehistoric sites of palaeolithic, mesolithic and neolithic origins have been discovered in the Siwalik hills of Dang district. The earliest inhabitants of modern Nepal and adjoining areas are believed to be people from the Indus Valley civilisation. It is possible that the Dravidian people whose history predates the onset of the Bronze Age in the Indian subcontinent (around 3300 BC) inhabited the area before the arrival of other ethnic groups like the Tibeto-Burmans and Indo-Aryans from across the border. Tharus, Tibeto-Burmans who mixed heavily with Indians in the southern regions, are natives of the central Terai region of Nepal. The first documented tribes in Nepal are the Kirat people, who arrived into Nepal from Tibet roughly 4000 to 4500 years ago and moved into the Kathmandu valley and southern parts of Nepal, before being made to retreat elsewhere by the invading Licchavis from India who ruled the Kathmandu valley in modern-day southern parts of Nepal. Other ethnic groups of Indo-Aryan origin later migrated to southern part of Nepal from Indo-Gangetic Plain of northern India. Stella Kramrisch (1964) mentions a substratum of a race of Pre-Dravidians and Dravidians, who were in Nepal even before the Newars, who formed the majority of the ancient inhabitants of the valley of Kathmandu. Legends and ancient times 
Although very little is known about the early history of Nepal, legends and documented references reach far back to the 30th century BC. Also, the presence of historical sites such as the Valmiki ashram, indicates the presence of Sanatana (ancient) Hindu culture in parts of Nepal at that period. According to legendary accounts, the early rulers of Nepal were the Gopālavaṃśi (Gopal Bansa) or "cowherd dynasty", who presumably ruled for about five centuries. They are said to have been followed by the Mahiṣapālavaṃśa or "buffalo-herder dynasty", established by a Yadav named Bhul Singh. The Shakya clan formed an independent oligarchic republican state known as the 'Śākya Gaṇarājya' during the late Vedic period (c. 1000 – c. 500 BCE) and the later so-called second urbanisation period (c. 600 – c. 200 BCE). Its capital was Kapilavastu, which may have been located either in present-day Tilaurakot, Nepal. Gautama Buddha (c. 6th to 4th centuries BCE), whose teachings became the foundation of Buddhism, was the best-known Shakya. He was known in his lifetime as "Siddhartha Gautama" and "Shakyamuni" (Sage of the Shakyas). He was the son of Śuddhodana, the elected leader of the Śākya Gaṇarājya. Kirat dynasty 
The context of Kirat Dynasty ruling in Nepal before Licchavi dynasty and after Mahispal (Ahir) dynasty are depicted in different manuscripts. Delineating the area between the Sun Koshi and Tama Koshi rivers as their native land, the list of Kirati kings is also given in the Gopal genealogy. By defeating the last king of the Avir dynasty Bhuwan Singh in a battle, Kirati King Yalung or Yalamber had taken the regime of the valley under his control. In Hindu mythological perspective, this event is believed to have taken place in the final phase of Dvapara Yuga or initial phase of Kali Yuga or around the 6th century BC. Descriptions of 32, 28 and 29 Kirati kings are found according to the Gopal genealogy, language-genealogy and Wright genealogy respectively. By means of the notices contained in the classics of the East and West, the Kiranti people were living in their present whereabouts for the last 2000 to 2500 years, with an extensive dominion, possibly reaching at one time to the delta of the Ganges. Licchavi dynasty 
The kings of the Lichhavi dynasty (originally from Vaishali in modern-day India) ruled what is the Kathmandu valley in modern-day Nepal after the Kirats. It is mentioned in some genealogies and Puranas that the "Suryavansi Kshetriyas had established a new regime by defeating the Kirats". The Pashupati Purana mentions that "the masters of Vaishali established their own regime by confiding Kiratis with sweet words and defeating them in war". Similar contexts can be found in 'Himbatkhanda', which also mentions that "the masters of Vaishali had started ruling in Nepal by defeating Kirats". Different genealogies state different names of the last Kirati king. According to the Gopal genealogy, the Lichhavis established their rule in Nepal by defeating the last Kirati King 'Khigu', 'Galiz' according to the language-genealogy and 'Gasti' according to Wright genealogy. In 641, Songtsen Gampo of the Tibetan Empire sends Narendradeva back to Licchavi with an army and subjugates Nepal. Parts of Nepal and Licchavi was later under the direct influences of the Tibetan empire. Notes

References

Sources
 

History of Nepal
Ancient Nepal