So the first thing to understand about the modern state of Germany is the Holy Roman Empire. The HRE was a grouping of independent states, princes, and cities that were all independent rulers under the umbrella of the empire. These states had varying degrees of power and influence, ranging from individual cities to large member nations like Austria. For about 350 years, the Hapsburg family of Austria rued the empire as the elected Emperors, making them the most powerful member of the empire. Then, in 1805, Napoleon defeated the armies of the HRE at the Battle of Austerlitz, effectively destroying the empire. Several states split off to create the Confederation of the Rhine outside of the empire. So after the fall of the empire, Germany was left as a large grouping of independent states with Prussia and Austria being the major two. Still remembering the empire and having ambitions of reuniting the country, the debate began as to how to reunite the German states. There were two main approaches, "Greater Germany", favored by Austria, that wanted to unify all cultural Germans into one state. The other, "Lesser Germany", favored by Prussia, was to include the northern German states and exclude Austria. They united into the German Confederation, a weak grouping of states that was divided by the rivalry between the major powers, Austria and Prussia. In 1848, revolutions destroyed the Confederation, leaving a smaller group led by Prussia in the north and a group led by Austria in the south. Complicating things, Prussia and the northern states were much more Protestant while the southern states were more Catholic. In 1866, the two alliances went to war, with the northern Prussian alliance defeating the Austrian alliance, establishing Prussia as the dominant German power. In 1867, Austria united with Hungary and Croatia to form the Austro-Hungarian Empire, made up of Germans in the Austrian territories and non-Germans in the Hungarian and Croatian lands. In 1871, fearful of a powerful unified Germany on their borders (as would turn out to be a justified fear) the French attacked the North German Confederation but the Prussians were prepared and easily defeated them. The southern German states that had been allied to Austria were disliked the French more than they disliked the Prussians so they joined the war on Prussia's side. After the quick defeat of France, the victorious allies, by this point almost all the German speakers in Europe, excluding Austria, met at Versailles and decided to unite formally, proclaiming the King of Prussia, William I the emperor of a united German Empire, making him Kaiser Wilhelm I.
So that's the story of HOW Germany united. Now as to why Austria was left out. As you could probably see from the story, Austria had dominated Germany and all the states for almost 400 years but had fallen in the 1800s. Prussia was on the rise and saw an opportunity to eclipse Austria. The religious and political rivalries simmered for the rest of the century, including the war in 1866. After that war, Prussia was the dominant state in Germany and began building close alliances with the northern states. Prussia's main rival was Austria and Prussia used their political and military power to push Austria out. So the clear answer was that Prussia and Austria were rivals and Prussia wanted to have unchallenged control of Germany. So the rivalries between Prussia and Germany ended in Austria being excluded from Germany so that Prussia could be the unchallenged head of a united German state. The main political maneuverer behind all this was the dynamic duo of Wilhelm I and his chancellor, Otton Von Bismarck. The way that the two of them worked together to make lasting alliances and isolate Austria is fascinating, making Bismarck one of the best diplomats and politicians of the 1800s, pretty much building a nation in a lifetime. He's closely related to the story of modern Germany, because Wilhelm I's grandson, Wilhelm II, fired Bismarck only 2 years after taking the throne, making his own choices and destroying the Empire after WWI. So there are a ton of interesting people involved here, it's worth learning about!