On a Google Home device, how does "Okay Google" work on the device and when it's sent to the cloud?

On a Google Home device, how does "Okay Google" work on the device and when it's sent to the cloud?