Sensory neurons in the skin express TRP channels such as TRPV1 channels, TRPM8, and others (see Voets et al 2004 for more information on how these channels work). Different sensory neurons express different combinations of TRP channels .
Changes in temperature shift the probability of whether these channels are open or closed. Opening or closing of ion channels changes the membrane potential of the sensory neuron, which changes the rate of action potentials which informs the rest of the nervous system about the temperature.
The TRP channels can have other ligands, as well, such as capsaicin or menthol. The activity of these ligands at temperature-sensitive receptors is why we perceive chilis or mustard to taste "hot" and menthol to feel "cold".
More generally, the nervous system typically responds to changes better than constant stimuli through adaptation. Therefore, if your hand is fairly cold and you touch something warm or hot, you will perceive a hotter stimulus than if your hand started out already warm.
There isn't really a thermocouple or temperature difference detector in the skin, just these two mechanisms: channels whose open probability is a function of temperature, and sensory adaptation which heightens perceptual sensitivity to changes in temperature.
Voets, T., Droogmans, G., Wissenbach, U., Janssens, A., Flockerzi, V., & Nilius, B. (2004). The principle of temperature-dependent gating in cold-and heat-sensitive TRP channels. Nature, 430(7001), 748-754.