I can't wrap my head around megacities, my country has around 17 million people and there are many cities around the world with the same or over the amount of population. I just can't understand how the population of a whole country can fit in a city
They can't, really. Most megacities have many urban cores, and often they formed from one city absorbing others, so they're basically many cities joined together. They often also don't function like other cities, or don't function at all - Dhaka, for instance, has terrible traffic.