It’s a long story. Initially, I would like to say that we, the current Vietnamese, are the descendants of the Viet peoples, who inhabited from present-day South China to present-day North Vietnam. They are called Bách Việt (literally, in the Sino-Vietnamese vocabulary, “Bách” means “hundred”, but you could understand as “many”). The origin of the word “Việt”. It used to be understood that “Việt” means “ax” because the Việt peoples used axes to cut down trees and hunt. However, archeological evidence shows that they developed agriculture up to a certain level.
(The map below just illustrates some of all Việt people)
After the unification of China by the Qin dynasty, Sinicization began. The Qin started eliminating and assimilating many Việt people. Only some Việt peoples could pass the process, they were Lạc Việt, Âu Việt, and Nam Việt. Lạc Việt and Âu Việt unified, becoming Âu Lạc, under the leadership of An Dương Vương. Then, Nam Việt (present-day Guangdong and Guangxi, provinces of China) conquered Âu Lạc, unifying the Việt people again. The following event is the Han dynasty’s conquest of Nam Việt.
(The map below was the territories of Nam Việt)
About 2000 years later, the first king of the Nguyễn dynasty, Gia Long, required the Qing dynasty that his country would be called Nam Việt. The purpose in this requirement was to conquer back Guangdong and Guangxi. Realizing this purpose, the Qing emperor at that moment was Jiaqing decided to changed the name, from “Nam Việt” to “Việt Nam”. Gia Long accepted it. However, his successor, Minh Mạng, deleted this name and called the country “Đại Nam”. More than one hundred years later, the Nguyễn dynasty collapsed. Vietnamese governments in the North (the Democratic Republic of Vietnam) and in the South (the State of Vietnam, then the Republic of Vietnam) adopted the name “Việt Nam”. And that name has been used up to today.