How do planes know what altitude they're cruising at?
Above Transition Altitude (e.g. this is 5000ft in Germany) the altitude is measured in flight levels (FL) - each FL equals 100ft and is measured above an artificial QNH of 1013,25 hPa.
If you cruise for example at FL380 that will be 38000ft above the pressure level of 1013,25 hPa. This system assures that 2 aircraft which are 10 FL apart (e.g. FL370 and FL380) always have the required separation of 1000ft.
During descent when passing Transition Level you will change your altimeter setting to local QNH which ATC will tell you.