The history of Germany is long and tortured, taking many detours over the centuries. The Holy Roman Empire, which developed after Charlemagne, was chiefly populated by ethic Germans and run by various German princes, who elected the Emperor.
http://en.wikipedia.org/wiki/Holy_Roman_Empire
When Austria was a strong nation state under the Habsburg dynasty, political calculations were designed to keep the northern German states small and divided, so as not to challenge Austrian primacy. When the Reformation came along, a further split arose between the northern Germans, who became mostly protestant, and the Austrians, who remained Roman Catholic, along with Bavaria. The Thirty Years War, 1618-1648, was a great, bitter conflict in central Europe, the likes of which would not be seen again until the Great War, 1914-1918.
The rise of France in the aftermath of the Thirty Years War also was a great impediment to seeing the various German principalities unite, since France was a natural enemy of the Germans even then. By keeping the German states small and squabbling, France had an easier time dealing with the rest of western Europe.
Over time, the power and influence of Austria declined due to a number of factors, like engaging in serial warfare in order to place other members of the Habsburg dynasty on neighboring thrones, while the northern German states, particularly Prussia, sought to increase their prestige, primarily at Austria's expense, and without antagonizing France.
The first great blow which Prussia struck at Austria was seizing and annexing Silesia in 1740, which act set Frederick II the Great on his course as one of the most important German kings.
http://en.wikipedia.org/wiki/German_dualism
The loss of Silesia further cemented the mistrust of the Austrians for their northern German brothers, but the expansion of Prussia was checked eventually by their wars with Russia and then revolutionary France under Napoleon. After Waterloo, the Prussian monarchy had entered a period of long decline until its fortunes were revived when Bismarck was appointed Chancellor by Wilhelm I in 1862. Bismarck brought an energy to discharging his duties, as well as a shrewd plan to make his king the dominant monarch in western Europe. Wilhelm had been trained as a soldier and acceded the throne only because his brother, Frederick Wilhelm IV, had died without issue. As a reluctant monarch, Wilhelm was only too happy to let Bismarck have a free hand in dealing with the affairs of state.
http://en.wikipedia.org/wiki/Otto_von_Bismarck
In short order, Bismarck fought the Danes (1864), vanquished the Austrians (1866), and humbled the French (1870-71) in lightning wars where the Prussians suffered few casualties. As a consequence of the last war with the French, France formed the Third Republic and Bismarck persuaded the chief German kings and princes to allow Wilhelm to be elected as German emperor. Bismarck pointedly kept the Austrians out of this process, not least because of their earlier defeat in 1866.
Although Germany was technically united under Kaiser Wilhelm after 1871, the largest German states retained a great degree of autonomy in the empire, chiefly Bavaria, Saxony, and Wuerttemburg, but the state with the largest land area and population was Prussia. The kings of Prussia would also be German emperors, and this state of affairs continued until 1918, when the German empire and the Austro-Hungarian empire both succumbed to defeat in WWI, and the various monarchies across the empire were abolished.
After 1918, Prussia, although now a republic, remained the largest state in Germany and would continue as such until it was finally abolished in 1947 by the Allies following Germany's defeat in WW II. After the war, there were great shifts of population as many Germans who formerly lived in the eastern parts of Germany were forcibly evicted by the Russians and the Poles who took over former German territory.
http://en.wikipedia.org/wiki/Prussia