If you'd like me to nerdsplain something that might help, here I go.
Your body has a "sleep cycle" where it goes from deeper sleep to lighter sleep (including REM stage) and back again. The average length of one cycle is 1.5 hours. If you wake up during a light-sleep phase, it's generally much easier and leaves you more energized. So if you were currently in a light-sleep phase and you had the option to sleep another 40 minutes or wake up now, you'd be better off choosing to wake up now. Otherwise you'd have time to fall into a deeper sleep before you wake up, which would make the waking-up experience more unpleasant and leave you more grumpy. There are apps that try to listen to your breathing/movement and estimate how deep of sleep you're in and wake you when you're in lighter sleep rather than waiting till the exact time you set your alarm to.