"As a nation-state, Germany did not come into being until the creation of the German Empire in 1871 from the various German-speaking states such as Prussia, ...
Bavaria, Saxony, Baden and Württemberg. By then each of the major states had formed its own state railway and these remained separate, albeit working increasingly closely together, until after the First World War. After 1815 the territory of Bavaria included the Palatinate, or Pfalz, which was west of the Rhine and bordered on France and became part of the newly formed German state of Rhineland-Palatinate in 1946.
The Royal Bavarian State Railways (Königliche Bayerische Staats-Eisenbahnen or K.Bay.Sts.B.) was founded in 1844. The organisation grew into the second largest of the German state railways (after that of the Prussian state railways) with a railway network of 8,526 kilometres (including the Palatinate Railway or Pfalzbahn) by the end of the First World War." - (en.wikipedia.org 30.01.2020)