There is nothing (mostly) magical about VLANs.
In the beginning, there were ethernet hubs. Everything connected to the hub could talk to each other (assuming proper L3 addressing) and life was good. However, all the devices connected were in the same Collision Domain. If two devices tried to talk at the same time, chaos erupted and various dance moves were enacted to avoid the meeting-somebody-in-a-hallway awkwardness.
Ethernet switches fixed that. The Collision Domain was no longer of concern. Instead, the Broadcast Domain became a concept. Now life was really good. Still, things could have been better. You really didn't need for every device to hear a noisy neighbor that was broadcasting non-stop. There was also security concerns if you had groups of devices that really shouldn't be able to talk to each other (like a thermostat and a DB server).
No problem. Simply purchase a switch for each logical group of devices to segregate them. This works fine in a server room or data center. However, what about the wiring closet on the north side of the third floor? There is a thermostat, time clock, security camera, and a half dozen PCs. Are you going to put 4 different switches in that closet just for that? Wouldn't it be cool if we could take that 48 port switch and treat it like it was 4 different switches. With VLANs you can. Any time you use VLANs on a switch, you can view it logically as multiple separate switches.
More in a moment.