Assuming the Mac is newer than about 2011, it can boot to Internet Recovery.
Cmd ⌘ Opt ⌥ R will direct it to Internet Recovery, or it will redirect itself from Cmd ⌘ R if there is no usable Recovery partition.
It does not boot to a full OS, only sufficient to make repairs or to re-install a full OS. It is, as you surmised, held in RAM.
This functionality is built into the hardware [it will work even if no drive is detected], but I don't know where exactly it resides.
It's always recommended to use a wired Ethernet connection for this. It ought to work over normal domestic WiFi but is less reliable, and will not work on a captive portal.
This is for Intel Macs.
The structure has changed somewhat for M1 Macs; you hold the power button at boot until you're presented with disk & gear icons. The gear loads recovery options.