Over the course of the Italian Wars of Unification, also called the "Risorgimento.
After the post-Napolenic restoration dismantled Napoleon's Kingdom of Italy and restored a half-dozen or so Italian states, societal pressures within Italy pushed the rulers of the Kingdom of Piedmont-Sardinia to fight a series of wars between 1848 and 1870 against Austria-Hungary, the Kingdom of the Two Sicilies, and the Papal States. The post-Napoleonic Congress of Vienna had assigned Italy's most vibrant northern regions, Lombardy and Venetia, to the Austrian Empire. Following a series of popular revolts in the Austrian-held Italian lands, the Kingdom of Sardinia-Piedmont intervened militarily in favor of the separatist rebels in 1848, however this resulted in a humiliating defeat. By 1852, the new King Victor Emmanuel II and his Prime Minister the Count of Cavour managed to secure a mutual defense treaty with France in exchange for Piedmontese participation in the Crimean War. After provoking the Austro-Hungarian Empire into attacking in 1859, the Kingdom of Piedmont was able to beat the Austrians with French help and secure the cession of Lombardy, while revolts in the minor Italian states led to new provisional governments staging plebiscites to join the Kingdom of Piedmont.
Giuseppe Garibaldi, a Piedmontese general who always characterized himself as a bit of a wild-card, then staged a semi-authorized military expedition to southern Italy in 1860, handily defeating the Kingdom of the Two Sicilies (helped, as in the north, by the citizenry in revolt) resulting in the Kingdom of Piedmont annexing the whole of the peninsula apart from the Latinum and Veneto regions. Victor Emmanuel II was proclaimed "King of Italy" and moved his capital to Florence.
In 1866, when the Austro-Prussian War broke out, the Kingdom of Italy intervened on the side of the Prussians. The Austro-Hungarian Empire, attacked on two fronts, was candidly defeated and ceded the Venetia to the new Italian kingdom.
There remained an open, "Roman Question" seeing as the new Italian government saw Rome as the Kingdom's rightful capital. However, the Count of Cavour, Victor Emanuel's Prime Minister and the mastermind behind unification, had only ever envisioned the unification of the north of Italy; the Franco-Italian alliance did not provide for an eventual attack on the Papal State, especially because the city of Rome was defended by a French garrison. However, in 1870 the Franco-Prussian War broke out, and the French garrison in Rome was redeployed elsewhere. The threat of a diplomatic incident with France now much diminished, the Italian Army attacked and easily overpowered Rome's defenders.
After the First World War, Italy was additionally granted the ethnically Italian regions of the Trentino, Friuli, and Istria, ceded by the dismantled Austro-Hungarian Empire. Italy was also granted the province of Alto-Adige/Südtirol, which didn't have any ethnic Italians but allowed for a natural land border with Austria. Italy was not granted Dalmatia, which had been an important war goal, a slight which fueled Italian irredentism and influenced the country's to nationalistic extremism in the 1920s. After the Second World War, Italy was forced to cede Istria to Jugoslavia.
The history and histerography of the Italian Unification Process is a somewhat delicate and controversial topic to this day. However, there are many general historical overviews you can look into if you'd like to learn more. A great source is Davis, John A. Italy in the Nineteenth Century, 1796-1900. Oxford: Oxford UP, 2000.