At the Yalta Conference, the major Allied powers (Great Britain, United States and Soviet Union) met to discuss what the world (and especially Europe) would look like after the war was over.
One of the things that was agreed was that Poland would not return to its prewar borders. Instead, the Soviet Union would keep the part of Poland that had been given to it in its treaty with Germany before the war started. Poland as a whole was to be in the USSR's sphere of influence.
Germany was to be divided into four parts. Each part would be run by one of the Allied powers (the three powers at the Yalta Conference and France). Berlin was also to be divided even though it was inside the Soviet zone.