Taken from wikipedia:
A GPS receiver calculates its position by precisely timing the signals sent by GPS satellites high above the Earth. Each satellite continually transmits messages that include
the time the message was transmitted
satellite position at time of message transmission
The receiver uses the messages it receives to determine the transit time of each message and computes the distance to each satellite using the speed of light. Each of these distances and satellites' locations define a sphere. The receiver is on the surface of each of these spheres when the distances and the satellites' locations are correct. These distances and satellites' locations are used to compute the location of the receiver using the navigation equations. This location is then displayed, perhaps with a moving map display or latitude and longitude; elevation or altitude information may be included. Many GPS units show derived information such as direction and speed, calculated from position changes.
In typical GPS operation, four or more satellites must be visible to obtain an accurate result. Four sphere surfaces typically do not intersect. [a] Because of this, it can be said with confidence that when the navigation equations are solved to find an intersection, this solution gives the position of the receiver along with the difference between the time kept by the receiver's on-board clock and the true time-of-day, thereby eliminating the need for a very large, expensive, and power hungry clock. The very accurately computed time is used only for display or not at all in many GPS applications, which use only the location. A number of applications for GPS do make use of this cheap and highly accurate timing. These include time transfer, traffic signal timing, and synchronization of cell phone base stations.
Although four satellites are required for normal operation, fewer apply in special cases. If one variable is already known, a receiver can determine its position using only three satellites. For example, a ship or aircraft may have known elevation. Some GPS receivers may use additional clues or assumptions such as reusing the last known altitude, dead reckoning, inertial navigation, or including information from the vehicle computer, to give a (possibly degraded) position when fewer than four satellites are visible.