How does Ribbon in SharePoint 2010 works?

A file called CMDUI.XML stays at the web front end which contains the Out-of-Box site wide Ribbon implementation i.e. all the Ribbon UI for the entire site. In addition to this you have a CustomAction for each ribbon component.

These CustomActions have CommandUIExtentions block which has CommandUIDefinitions and CommandUIHandlers which make up the activity of the ribbon component.

So, when the ribbon is loaded the CommandUIDefinition merges with Out-of-Box definition in the CMDUI.XML