History: the University of Oxford pre-dates its colleges. Scholars began to gather at Oxford, an established market town at a river crossing, at a date which is now uncertain about 900 to 1000 years ago. Houses to accommodate the students grew up. In the thirteenth century, Bishops, Monarchs, and wealthy individuals started to endow colleges, in which students could live and study in a quasi-monastic way (at that time the main study was Theology, but study of philosophy, classical languages, law, and eventually science and medicine followed on).
Early colleges provided living space, a library, a chapel, and a hall for dining and debating. This remains the basic model of a college, now supplemented by seminar rooms, performance spaces, sports grounds, gardens, and so on.
Scholars proceeded to become Bachelors, then Masters, then Doctors. This is why Oxford undergraduates are awarded BAs in all subjects, and can become MAs automatically some time later. Oxford provided graduates to staff the Church, the Civil Service, and the Law. Later, Oxford became a fashionable place for the sons of the gentry and aristocracy to study.
Medieval colleges look like fortified houses because they are. Violent conflicts between students and townspeople led to the colleges locking their doors.
Cambridge started 800 years ago when some scholars from Oxford moved to Cambridge, then a small town in the Fens, because of plague and/or conflict.
After a failed attempt to start a third university at Stamford, Oxford and Cambridge remained the only two universities in England until the foundations of the collegiate Universities of London and Durham in the early nineteenth century. In Scotland, St Andrew's, Edinburgh, and Glasgow are the oldest universities but are not collegiate.The University of Dublin was intended to be a collegiate university but Trinity College was and is its only college. The same is the case at Harvard in the US, founded in the early C17 by Cambridge graduates. Wales had no universities before the late C19/early 20.
The modern idea of a university developed in the nineteenth century. Women's colleges were founded in the late C19, and Oxford and Cambridge admitted women to the University in the early and mid C20. The universities gradually became more meritocratic in their admissions procedures, and now entry can only be obtained by competing on academic merit.
Factoid: until the mid C20 the universities of Oxford and Cambridge had their own Members of Parliament.