Before Nepal's emergence as a nation in the latter half of the 18th century, the designation 'Nepal' was largely applied only to the Kathmandu Valley. Thus up until the unification of the country, Nepal's history is largely the history of the Kathmandu Valley. References to Nepal in famous Hindu epics such as the Mahabharata, Puranas and also Buddhist and Jain scriptures, establish the country's antiquity as an independent political and territorial entity. The Vamshavalis or chronicles, the oldest of which was written during the 14th century, are the only fairly reliable basis for Nepal's ancient history. The Vamshavalis mention the rule of several dynasties the Gopalas, the Abhiras and the Kiratas -- over a stretch of centuries. However, no extant historical evidence has yet authenticated the rule of these legendary dynasties. The documented history of Nepal begins with the Changu Narayan temple inscription of King Manadeva I (C 464-505 A.D.) of the Lichavi dynasty.
Narendradeval another Lichavi king, initiated friendly relations with China and his successors laid the foundations of friendship with India by entering into matrimonial alliances with the Indian royal families. The Lichchhavi rule spanned over a period of about 630 years, the last ruler being Jayakamadeva.
After the fall of the Lichchhavis came the Malla period during which the foundation of the city of Kantipur (later Kathmandu) was laid. The early Malla rule started with Ari Malla in the 12th century and over the next two centuries grew into a large empire before disintegrating into small principalities which later became known as the Baisi (i.e. the twenty-two principalities). This was more or less coincidental with the emergence of the Chaubisi (i.e. twenty-four principalities). The history of these principalities remains shrouded up until the time when they joined other kingdoms, both large and small, to form the unified Kingdom of Nepal.

Shah Dynasty, Unification of Nepal
Prithvi Narayan Shah (c 1769-1775), with whom we move into the modern period of Nepal's history, was the ninth generation descendant of Dravya Shah (1559-1570), the founder of the ruling house of Gorkha. Prithvi Narayan Shah succeeded his father King Nara Bhupal Shah to the throne of Gorkha in 1743 AD. King Prithvi Narayan Shah was quite aware of the political situation
of the Valley kingdoms as well as of the Barsi and Chaubisi principalities. He foresaw the need for unifying the small principalities as an urgent condition for survival in the future and set him self to the task accordingly.
His assessment of the situation among the hill principalities was correct, and the principalities were subjugated fairly easily. King Prithvi Narayan Shah's victory march began with the conquest of Nuwakot, which lies between Kathmandu and Gorkha, in 1744. After Nuwakot, he occupied strategic points in the hills surrounding the Kathmandu Valley. The ValleyÕs communications with the outside world were thus cut off. The occupation of the Kuti Pass in about 1756 stopped the ValleyÕs trade with Tibet. Finally, King Prithvi Narayan Shah entered the Valley. After the victory of Kirtipur. King Jaya Prakash Malla of Kathmandu sought help from the British and so the East India Company sent a contingent of soldiers under Captain Kinloch in 1767. The British force was defeated at Sindhuli by King Prithvi Narayan ShahÕs army. This defeat of the British completely shattered the hopes of King Jaya Prakash Malla. The capture of Kathmandu (September 25. 1768) was dramatic. As the people of Kathmandu were celebrating the festival of Indrajatra, Prithvi Narayan Shah and his men marched into the city. A throne was put on the palace courtyard for the king of Kathmandu. Prithvi Narayan Shah sat on the throne and was hailed by the people as the king of Kathmandu. Jaya Prakash Malla managed to escape with his life and took asylum in Patan. When Patan was captured a few weeks later, both Jaya Prakash Malla and the king of Patan, Tej Narsingh Mallal took refuge in Bhaktapur, which was also captured after some time. Thus the Kathmandu Valley was conquered by King Prithvi Narayan Shah and Kathmandu became the capital of the modern Nepal by 1769.
King Prithvi Narayan Shah was successful in bringing together diverse religio-ethnic groups under one national. He was a true nationalist in his outlook and was in favor of adopting a closed-door policy with regard to the British. Not only his social and economic views guided the country's socio-economic course for a long time, his use of the imagery, 'a yam between two bouldersÕ in Nepal's geopolitical context, formed the principal guideline of the country`s foreign policy for future centuries.
The War with British - The Nepalese had differences of opinion with the East India Company regarding the ownership of the land strip of the western Terai, particularly Butwal and Seoraj. The outcome of the conflict was a war with the British. The British launched their attack on the Nepali forces at Nalapani, the western most point of Nepal's frontier at the close of 1814. Though the Nepalese were able to inflict heavy losses to the British army on various fronts, the larger army and the superior weapons of the British proved too strong. The Nepali army evacuated the areas west of the Mahakali river and ultimately the treaty of Sugauli was signed with the British in 1816. Among other things, this treaty took away a large chunk of the Terai from Nepal and the rivers Mahakali and Mechi were fixed as the country's western and eastern boundaries. At this time, King Girvana Yuddha Biktram Shah was on the throne of Nepal, and the power of state was in the hands of Prime Minister Bhimsen Thapa who wielded enormous power during the rule of King Girvana Yuddha Bikram Shah and his son King Rajendra Bikram Shah.