How does a spacecraft know its orientation while in orbit? For example, turning from prograde to retrograde when starting a descent? I am wondering if there is any way to sense this without using an external reference, like recording two known points on earth some time apart and then using this to calculate the orbit.
In LEO, nowadays? Easy, GPS and compass (actually, a multi-axis magnetometer or a gyrocompass).
Now if it's in orbit of other bodies, or in interplanetary space... or was a craft before GPS... that gets more interesting.
Let me paste a rather long but quite comprehensive summary of the devices used, from the Attitude Control article on Wikipedia.
A horizon sensor is an optical instrument that detects light from the 'limb' of Earth's atmosphere, i.e., at the horizon. Thermal infrared sensing is often used, which senses the comparative warmth of the atmosphere, compared to the much colder cosmic background. This sensor provides orientation with respect to Earth about two orthogonal axes. It tends to be less precise than sensors based on stellar observation. Sometimes referred to as an Earth sensor.
Similar to the way that a terrestrial gyrocompass uses a pendulum to sense local gravity and force its gyro into alignment with Earth's spin vector, and therefore point north, an orbital gyrocompass uses a horizon sensor to sense the direction to Earth's center, and a gyro to sense rotation about an axis normal to the orbit plane. Thus, the horizon sensor provides pitch and roll measurements, and the gyro provides yaw. See Tait-Bryan angles.
A sun sensor is a device that senses the direction to the Sun. This can be as simple as some solar cells and shades, or as complex as a steerable telescope, depending on mission requirements.
An Earth sensor is a device that senses the direction to Earth. It is usually an infrared camera; nowadays the main method to detect attitude is the star tracker, but Earth sensors are still integrated in satellites for their low cost and reliability.
A star tracker is an optical device that measures the position(s) of star(s) using photocell(s) or a camera.
A magnetometer is a device that senses magnetic field strength and, when used in a three-axis triad, magnetic field direction. As a spacecraft navigational aid, sensed field strength and direction is compared to a map of Earth's magnetic field stored in the memory of an on-board or ground-based guidance computer. If spacecraft position is known then attitude can be inferred.
In case of probes in interplanetary space these are insufficient. In this case the probe can use a star tracker to determine its own attitude, but the position is determined on Earth - radio signals from the probe are triangulated, precise distance (to within meters or less!) can be determined using phase shift, and then the probe receives its calculated position back from Earth.