Note: There are different kinds of confidence ratings (eg, confidence in skill or ability, confidence in knowledge or expertise, etc). This answer only addresses the question as asked, regarding confidence in memory or familiarity.
Processing fluency - sometimes referred to as "cognitive fluency", "cognitive ease", or just "fluency" - is a mechanism proposed to underlie confidence ratings about familiarity:
... perceptual fluency can contribute to the experience of familiarity
when fluent processing is attributed to the past. ... Jacoby and
Dallas in 1981 argued that items from past experience are processed
more fluently. ... people sometimes take fluency as an indication that
a stimulus is familiar even though the sense of familiarity is
false. Perceptual fluency literature has been dominated with
research that posits that fluency leads to familiarity.
Processing fluency, as investigated by Hertwig et al (2008), refers to latency - ie, the speed with which processing occurs. They demonstrate that the human mind is able to discriminate retrieval (response) latencies with great accuracy (down to 100ms), and these latencies correlate strongly with recognition confidence ratings.