El Cid's early life
Rodrigo Diaz de Bivar was born to Diego Lainez, a member of the minor gentry, sometime between 1043 and 1045. He was educated and brought up by the Castilian royal family as a favor to Lainez. Diaz spent much time with the prince Sancho II, and when he ascended to the throne, he greatly expanded the Spanish Empire. Rodrigo earned the title "El Campeador" after defeating an Aragonese knight in single combat. Since Diaz's unit of Castilians was allied with a large number of Moors, the Moors took a liking to him and called him "Al-Sayyid", meaning "The lord". It is from this we get his title, "El Cid".
Serving the Brother
When Sancho was assassinated (most likely by his brother), Alfonso VI took control of both Castile and Leon. Alfonso was wary of El Cid, which is understandable, as he was quite possibly the most popular man in Castile. El Cid proved himself a loyal follower, and even married Alfonso's niece Jimena. But after an unauthorized move into Moor-held Granada, El Cid was exiled from Castile. But this was not the end of El Cid.
El Cid, Mercenario
Obviously, such a man of great fighting prowess and stategic ability was a hot commodity. Indeed, he was hired by the Moorish ruler of Zaragosa, al-Mu'tamin, and Diaz served both him and his successor, al-Mu'tamin II, faithfully. However, in 1068, the Berber invasion of Spain, led by Yusuf I, began. Alfonso's armies were crushed, and he called back the best general he knew, El Cid Campeador. El Cid crushed the Almoravids, and was summarily sent back into exile.