At the end of World War 1 Germany was defeated and subjected to numerous restrictions on its military as well as war reparations to the Allies that devastated its economy. This state of affairs contributed to the rise of the Nazi Party and a German foreign policy aimed at regaining lost territory and greater expansion.
The war also ended with the collapse of the Tsarist regime in Russia. Out of the various factions that created a provisional government, the Bolshevic communists emerged victorious and founded the Soviet Union. The capitalist states of Western Europe and the U.S saw the communist regime as a direct threat to their global power and worked to isolate them internationally.
When Hitler took power in Germany he immediately began building up the military and annexed Austria and part of Czechoslovakia. France and Britain attempted several diplomatic efforts to prevent another European war. They also signed a treaty with Poland vowing to come to its aid if it was invaded by a foreign power.
The Nazis were even more hostile to the Soviet Union than other Western states due to their ideological rejection of communism and their racist convictions that saw many Eastern Europeans, particularly Slavic peoples, as genetically inferior.
So it was a shock to the Allies when Germany and Russia signed a non-aggression pact, formally agreeing not to attack each other for 10 years, and not to aid any third power that may attack the other. One of the main reasons many argue that Germany lost the first World War was that it was fighting states on either side of it. The Molotov-Ribbentrop Pact seemed to ensure that would not happen again, making war with Western Europe more likely. Soon after the pact was signed Germany invaded Poland, beginning the second World War. 2 weeks later Russia invaded Poland from the east.
At the end of the war it was revealed that there was a secret protocol included in the Molotov-Ribbentrop Pact that specified how Germany and Russia would carve up Eastern Europe into separate spheres of influence, including the division of Poland between them.
The pact was dissolved in 1941 when the Nazis invaded the Soviet Union in a surprise attack known as “Operation Barbarossa.” Most historians argue that despite Hitler and the Nazis’ deep hostility to communism and racist stance towards Slavic peoples, Stalin and the leadership of the Soviet Union were genuinely caught off guard by the invasion. Initial gains by Germany were soon bogged down in arguably the most vicious fighting of the war. Many battle sites on the eastern front, such as Stalingrad, still bear devastation directly related to the constant bombardment. 27 million Russians died in World War 2- approximately 19 million civilians and 9 million military personnel.
Sources:
Molotov-Ribbentrop: The Pact That Changed Europe's Borders-
Radio Free Europe
German-Soviet Pact- The Holocaust Encyclopedia
The Molotov-Ribbentrop pact – Archive- The Guardian