That is such a huge question...
M365 is a service that lives on top of Azure, providing collaboration and communications tools, along with a horde of automation tools.
Azure is the fabric the M365 runs on itself... with an ecosystem of products larger than any single human could ever know all at once that does literally anything you can imagine. But on a simplistic level it's a space to rent virtual hardware from Microsoft to do things... Like running a VM that houses some line of business app so you don't need on prem hardware anymore. It's a virtual datacenter that can move workloads anywhere on the planet at a click.
It scales from a single datacenter providing access to a VM all the way up to load balanced and clustered international scale workloads that wouldn't fall down if half the planet is on fire.
What does it do? It's easier to answer what it doesn't do... or What is cost effective to do? That's the really big one.