The short answer
Before satellite positioning, ships worked out their location by starting from a known point and estimating how far they had moved. They then checked that estimate against the sun, the stars, the coastline and the depth of the water. The estimate is called dead reckoning, and it was often combined with other methods.
Dead reckoning
The dead reckoning navigation technique works from a known starting position. The navigator records the heading, usually from a compass, along with the speed and the time elapsed. From these, the navigator works out a new estimated position on the chart.
Small errors in heading or speed build up over time, so navigators corrected the estimate whenever they could get a better fix. Dead reckoning was useful, but it was never considered reliable on its own for long passages.
Celestial navigation
A sextant measures the angle between a celestial body, such as the sun, a planet or a star, and the horizon. Using the time of the observation and printed tables, the navigator calculated a line of position.
Latitude could be found with reasonable accuracy from the sun at noon or from the North Star in the Northern Hemisphere. Longitude was harder, because it depended on knowing the exact time at a reference point. Accurate marine chronometers, which became reliable in the 1700s, made longitude practical at sea.
Coastal piloting and depth soundings
Near the coast, sailors used landmarks, lighthouses and compass bearings taken to headlands. They also used a lead line, a weighted rope marked at intervals, to measure the depth of the water. Comparing the depth with the chart helped confirm where the ship was.
Radio and radar
From the early 1900s, radio direction finding let ships take bearings on radio stations at known positions. Loran, a radio navigation system developed during World War II, gave ships and aircraft position lines from fixed transmitters. Radar could measure the range and bearing to coastlines and other ships, which helped in poor visibility.
How the methods were combined
Navigators rarely relied on one method. They combined two or more lines of position, taken at about the same time, to get a fix. Where the lines crossed, the ship was likely to be. This combination of methods is the core of how ships knew where they were before GPS.
Why GPS changed things
The US Global Positioning System reached full operational capability in 1995. It gives a position directly from satellite signals, which removed much of the work of estimating and plotting. The older methods remain part of navigation training, because they still help when electronic systems fail.