Sabuktigin was the founder of the Ghaznavid dynasty.
Descended from a Sassanid general who established himself a ruler of Transoxania, the Samanid Dynasty in 960 CE found itself torn between two military families, one of which was headed by the Turkic general Alptigin, who had used his influence to conquer eastern territories and establish himself as a provincial governor at Ghazna (modern Ghazni in Afghanistan). When the Samanid Emir Abu ol-Hasan died in 961 CE and Alptigin's candidate was rejected by the court ministers, he retired from Khurasan (northeastern Iran) to Ghazna, where he ruled as a largely independent sovereign, thus starting the Ghaznavid list in 962 CE.
Alptigin's son-in-law Sebuktigin succeeded him in 977 CE and was recognized as governor of Ghazna by the Samanids. Sebuktigin consolidated and expanded his kingdom eastward to the Indian border, which prompted the Shahi prince Jayapala of Waihind to launch a preemptive strike at Ghazna. Jayapala was defeated and forced to pay a large tribute, and when he defaulted and mobilized a new army, he was defeated again.
Sebuktigin died in 997 CE and was succeeded by his famous son, Mahmud in 998 CE. Only 27 and a staunch Moslem, Mahmud of Ghazna took the title Emir in deference to the Abbasid Caliphate in Baghdad who legitimized his rule. He also adopted the title Sultan, signalling clearly his independence from the Samanids. By diplomacy, he made a treaty with the Qarakhanids (Ilek Khanate) recognizing a boundary along the Oxus River that effectively split the territory of the Samanids. In 999 CE, the Ghaznavids defeated the Samanids (laying claim to Khurasan) and the Qarakhanids captured Bukhara, the Samanid capital.
With his kingdom secure, and with encouragement from the Caliph, Mahmud turned his attentions eastward in 1001 CE, vowing to invade India once a year to bring the word of Allah to the Hindu kingdoms of India by fire and sword.
His first major campaign in northern Indian was against Jaipal, the Hindu ruler of the Punjab. In battle near Peshawar, Mahmud's 15,000 Ghulam cavalry routed Jaipal's army of 12,000 horse, 30,000 foot and 300 elephants, leaving nearly half their number dead. Jaipal was captured and released to rule as a tributary, but was so grief-stricken by his defeat and despised by his people for it, that he abdicated in favor of his son Anandpal and immolated himself on his own funeral pyre.
It took several years, but Anandpal was able in 1008 CE to raise a large army with contingents from the Hindu princes of Ujjayan, Gwalior, Kalinjar, Kannaws, Delhi, and Ajmerand to take the field against Mahmud. The respective armies encamped at Peshawar and Und for 40 days, challenging each other to engage. When the battle finally materialized, Mahmud found his army hard pressed by the fierce attack of Khokar tribemen on both flanks when a stray arrow panicked Anandpal's elephant causing it to flee the field. Seeing their leader in apparent flight broke the morale of the Indian army and ensured Mahmud's decisive victory.
Mahmud launched a total of 17 campaigns into Indian between 1001 and 1026 CE, annexing the Punjab, establishing a provincial governor at Lahore, and consolidating northeastern Indian before looking south. The Indian kingdoms of Nagarkot, Thanesar, Kannawj and Kalinjar were all conquered and left in the hands of Hindu vassals. With the tribute and plunder gained from his campaigns, he transformed Ghazna into one of the leading cities of Central Asia, patronizing scholars, establishing colleges, laying out gardens, and building mosques, palaces, and caravansaries.
In his last Indian campaign in 1024 CE, Mahmud reached the southern coast of Kathiawar along the Arabian Sea, where he sacked the city of Somnath and destroyed its famous Hindu temple to Shiva (whose mystical idol was apparently levitated by magnetic forces).