The situation is quite complex, and there are certain things that we do not fully understand, but I will try to give you an explanation.
First of all, at the cellular level, you have the genetic components of the circadian clock, the clock genes and their protein products.
You can divide clock proteins into positive and negative regulators: the positive regulators modulate transcription of clock-controlled genes and are inhibited by the negative regulators in a loop that lasts approximately 24 hours (in Latin: circa = around and dies = day).
For instance the Clock and Bmal1 nuclear proteins, when present in sufficiently large amount, will dimerize and act as transcription factors on a series of genes that contain a region in their promoter element called E-box. Amongst these are the Period (Per) genes.
Per is then synthesised, and exported to the cytoplasm. Here, if in a sufficiently large amount, it can heterodimerize with the Cryptocrome (Cry) proteins: the dimer will then enter the nucleus and inhibit the transcription actions of the Clock/Bmal couple. This will in turn, block the transcription of Per, that will therefore not be able to dimerize with Cry and stop the inhibition of Clock/Bmal and so on. All of this takes approximately 24 hours.
This basic loop (and some more) is nicely schematised in this review by Reppert and Weaver
Coordination of circadian timing in mammals. - Reppert and Weaver, Nature. 2002 Aug 29;418(6901):935-41.
I report here the legend of the figure:
The clock mechanism comprises interactive positive (green) and negative (red) feedback loops. CLOCK (C, oval) and BMAL1 (B, oval) form heterodimers and activate transcription of the Per, Cry and Rev-Erbalpha genes through E-box enhancers. As the levels of PER proteins increase (P, blue circle), they complex with CRY proteins (C, diamond) and CKIε/CKIδ (ε/δ, circle), and are phosphorylated (p). In the nucleus, the CRY–PER–CKIε/CKIδ complexes associate with CLOCK–BMAL1 heterodimers to shut down transcription while the heterodimer remains bound to DNA, forming the negative feedback loop. For the positive feedback loop, increasing REV-ERBα levels (R, circle) act through Rev-Erb/ROR response elements in the Bmal1 promoter to repress (-) Bmal1 transcription. CRY-mediated inhibition of CLOCK–BMAL1-mediated transcription de-represses (activates) Bmal1 transcription, because REV-ERBα-mediated repression is inhibited. An activator (A, circle) may positively regulate Bmal1 transcription (?) alone or by interacting with mPER2. There are probably kinases (?) other than CKIε and CKIδ that participate in phosphorylation of clock proteins.
The clock machinery, however, is even more complex than this and different tissues need to integrate different signals (e.g. light, hormonal concentrations and so on).
However, as nice as this may be, our bodies are not constituted by one single cell... if we "zoom out" a little bit and we go to the tissue or the whole body level, we see that circadian rhytms are present in all sorts of tissues and involve all sorts of different physiological processes. A very interesting question is then: how do cells from different organs coordinate each other so that the interrelation of different circadian processes is always the same? For instance, the release of cortisol peaks in the morning, our body temperature has a peak in the late afternoon and a trough in the early hours of the morning, and our heart rate is higher during the daytime.
In 1972, an article by Moore and Eichler was published, showing that lesioning the suprachiasmatic nucleus (SCN) of the hypothalamus (a region at the base of the brain) resulted in the "breakage" of the circadian rhythm of corticosterone (the stress hormone).
Loss of a circadian adrenal corticosterone rhythm following suprachiasmatic lesions in the rat. - Moore and Eichler, Brain Res. 1972 Jul 13;42(1):201-6
The fact that lesioning a bit of the brain resulted in loss of circadian rhythm in the adrenal gland was obviously a very big deal: the central circadian clock of the organism had been discovered.
I will not going too much into that but, since 1972 many advances have been made and nowadays we know that, although the role of the SCN is very important, it is not the only clock in the body. Several peripheral clock exist, in organs such as the pituitary gland, the liver or the pancreas. How all these clocks communicate between each other and what is their contribution to the generation of non-circadian rhythms (ultradian and infradian) are questions that still have to be solved.
A few interesting papers on the matter:
A riot of rhythms: neuronal and glial circadian oscillators in the mediobasal hypothalamus. - Guilding et al., Mol Brain. 2009 Aug 27;2:28.
A clockwork web: circadian timing in brain and periphery, in health and disease. - Hastings et al., Nat Rev Neurosci. 2003 Aug;4(8):649-61.
Peripheral circadian oscillators in mammals: time and food. - Schibler et al., J Biol Rhythms. 2003 Jun;18(3):250-60.