Nest knows when your phone enters or leaves the Nest Thermostat's wifi network linked to your Nest account.
Nest looks at many signals – including Bluetooth or ZigBee third-party devices, your Nest history, and Nest Leaf. Nest also uses a proprietary test called Nest Signal to make its best guess about whether you're home or not.
The Nest Thermostats that are installed in the US currently use a Network Time Protocol (NTP) connection to a trusted time server on the Internet. Nest Thermostats outside of the US (currently the UK and Canada only) use GPS for Nest Signal instead of NTP.