Google Authenticator uses a TOTP–Time-based One Time Password–algorithm. It’s pretty simple. After an initial setup routine that generates or lets you input a shared secret, the app is ready to go. After this initial connection, no further connection to the server is required. The six-digit OTP is generated using a combination of the shared secret, the current time, and a signing function. Basically, as long as the time on your phone is accurate, the server is able to generate the same code your phone is generating. This changes every minute. When you actually use the OTP, it is compared with what the server says it should be and if they match, you are authenticated.
If you really want to get into the details, you can read the IETF RFC 6238 which tells how it all works.