Phones can typically provide location information to different levels of accuracy (configured in settings).
Network-based location approximates the location by combining the known locations of mobile network cell tower sites with information such as signal timings.
Satellite-based location (high accuracy) relies on radio signals received from a network of satellites orbiting the earth.
There are a number of global and regional satellite systems. GPS (Global Positioning System) satellites are owned by the United States government. Many phones support other satellite systems, including GLONASS (Russia), BeiDou (China), Galileo (Europe) and QZSS (Japan). Phones may use a combination of satellites from different systems to obtain a position fix (e.g. GPS and Glonass).
GPS requires line of sight to GPS satellites to receive the signal from the satellite, i.e. outdoors (or at least near a large window). At regular intervals, the satellites transmit information about their position, along with the current time. Based on this information, the GPS receiver in your phone calculates the distance to each satellite. With this information from at least 3 satellites, the GPS receiver can accurately determine the location using some geometry (trilateration). GPS uses quite a lot of power (hence phone battery).
Cell phones use A-GPS (network assisted GPS) to help shorten the time to fix onto satellites and to improve accuracy. A cell phone with no network connection will not have the benefit of this assistance (e.g. the network can’t provide GPS satellite orbital data to reduce the time to fix onto a GPS satellite).
It is interesting to note that on Android some people use fake GPS location apps to bypass the GPS receiver location. This works by exploiting an Android feature meant for developers to test their apps in different locations (to “mock” a location). When a mock location app is installed, Android uses the mock GPS location from the specified app, rather than the location from GPS receiver.