In the periphery (e.g. on our fingertips), our body senses external temperature through nerve terminals, expressing certain TRP channels. These are ion channels that are sensitive to temperature (note that TRP channels can be sensitive to several things, such as pH, light, and stretch) and allow entrance of cations in the cell when the temperature is higher or lower than a certain threshold.
Six TRP channels have been described as been involved in sensing different temperature ranges1,2:
- TRPV1 is activated at >43 °C
- TRPV2 at >52 °C
- TRPV3 at ~> 34-38 °C
- TRPV4 at ~> 27-35 °C
- TRPM8 at ~< 25-28 °C
- TRPA1 at ~< 17 °C
Not surprisingly, TRPV1 and TRPV2 are also involved in nociception (=pain perception).
The exact molecular mechanisms by which different temperatures open different TRP channels are unclear, although some biophysical models have been proposed.3
I am not sure of the exact "format" in which sensory fibers encode different temperature, but I would assume that the neuron would fire faster the more the temperature is distant from the specific threshold (hot or cold).
1 Thermosensation and pain. - J Neurobiol. 2004 Oct;61(1):3-12.
2 Sensing hot and cold with TRP channels. - Int J Hyperthermia. 2011;27(4):388-98.
3 - Thermal gating of TRP ion channels: food for thought? - Sci STKE. 2006 Mar 14;2006(326):pe12.