What were the advantages for Germany and the Soviet Union in signing the Nazi-Soviet non-aggression pact?
First, let's look at the advantages for Germany. Hitler did not want Germany to have to fight a two-front war like it did in World War I, as this led to a war of attrition that Germany was doomed to lose. By signing a non-aggression pact with the Soviet Union, Hitler was sure he would not be attacked from his Eas, allowing him to focus his defensive efforts to his West. Hitler used the Versailles Treaty as an excuse to go to war and claim half of Poland, which used to be part of the German Empire under Kaiser Wilhelm II before World War I. Hitler invaded Poland on September 1, 1939, causing France and Britain to declare war.
Now, for the advantages gained by the Soviet Union. Stalin knew the German army was formidable and that the Soviet Union was not yet ready to fight. This was partly Stalin's own fault for having liquidated (killed) most of his top generals in the show trials of 1937. Stalin had designs on the Baltic countries, Finland, and eastern Poland — lands that belonged to the Russian Empire in the time of the czars. The agreement Stalin reached with Hitler was that Stalin would invade the Baltic countries and Poland at the same time Hitler invaded Poland. Stalin invaded Poland and created a buffer state it would control for over forty years.