A machine is a device that uses energy to perform work. Typically by applying or transforming force, motion, or both.
The space shuttle can be thought of maybe as a collection of machines working in concert, but thinking of it as ONE machines renders the meaning of machine less useful.
In my understanding a device has its origin in giving advice and does something specific for you (a pen is a writing device, a mixer is a cooking device, a phone is a communication device, a bus is a transportation device etc.).
A machine on the other hand has its roots in its mechanisms. It physically transforms something by applying mechanical power, and that's not necessarily done for you (e.g. printing device VS printing machine).
Whether a device can be composed out of many smaller devices, or whether a machine can be composed out of many smaller machines just doesn't seem to be relevant. That being said, language evolves with time and certain concepts find some overlap in general usage.
Device comes from Latin dividere, meaning "something which is divided". Later with old French devis (disposition, desire, purpose, or decorative emblem) and deviser (arrange, plan). A device is something planned, designed, potentially intricate. A device doesn't always need to be mechanical/physical as there are "literal devices" and one can be "left to their devices". I'd say "device" is more like "a planned thing" if giving a basic definition.
A machine is almost always a device, but a device isn't always a machine. A fancy earring can be a device, but it is clearly not a machine.
The space shuttle can be thought of maybe as a collection of machines working in concert, but thinking of it as ONE machines renders the meaning of machine less useful.