The speed of sound is solely determined by the density of the medium though which it travels, and air density changes with its temperature, pressure and humidity. The higher the pressure or lower the temperature or humidity, the denser the air, and the faster the speed of sound. (Unless the altitude is high or the day is really muggy, humidity has a negligible effect on density, so we'll ignore it for the rest of this.) Pressure is inversely related to altitude; the higher you go the less pressure there is. Unfortunately, temperature is also inversely related to altitude; the higher you go the colder it gets. This makes the determination of the speed of sound at a particular altitude a two step process.
First, we determine what the "effective" altitude is based on our current altitude and temperature. From that we can determine the density of the air and therefore the speed of sound. Effective altitudes are measured against standard atmosphere, which at sea level is 59ºF with a density of 0.00237 slugs per cubic foot (15ºC, 1.225 kilograms per cubic meter). As altitude increases, the standard atmostphere gets colder and less compressed. If we assume these standard atmosphere conditions exist at sea level, then at 5,000 feet (1,525 meters) the temperature falls to 41.2ºF (~5ºC) and the density drops to 0.00204 sl/ft3 (1.056 kg/m3), a seemingly significant change.
Standard atmosphere's behavior in this way has been distilled down to a handful of equations that can fairly accurately approximate the temperature and pressure at any given altitude to the edge of space (~45 miles). Airplane pilots need to know this so they can figure out how much lift their wings will generate under the prevailing conditions at their airport.1 This "effective altitude" is actually called the density altitude, becuase its the altitude in standard atmosphere at which that density exists. Once we know the density altitude, we know the air density and can derive the speed of sound.
Properties Of The U.S. Standard Atmosphere 1976 - All the details on standard atmosphere