Thomas Pakenham’s excellent The Scramble for Africa (probably the best overview of that period in Africa, IMHO) goes into great detail about how Britain (and France, and Germany, and later Belgium) found themselves with a Colonial Empire in Africa.
As much of an ardent Colonialist and Imperialist as I am, the best I’ve been able to come up with as to why it happened is this:
It Seemed Like A Good Idea At The Time.
The idea at first (as FRDE says) was simply to establish trading posts (on places like the Oil River in Nigeria) and exchange shiny baubles, cloth, and guns with the natives for things like palm oil, ivory, rubber, and other things not readily available in Europe at the time- but once the Scramble For Africa kicked off it was all downhill from there, as far as the Africans were concerned, at any rate. Basically, Britain and France were, by the 1880s or so interested (in relation to Africa) in the Three Cs: Commerce, Christianity, and Civilisation (Which included the eradication of the Slave Trade). And if the Natives had a problem with that, well, as Hilaire Belloc said: “We have got the Maxim Gun/And They Have Not”
Overseas Military Adventures were expensive- the Anglo-Zulu War cost some unfathomable sum of money and the Sudanese Campaign was even more expensive (and embarrassing for much of it). The Boer War cost the Crown an ungodly sum of money as well, and that’s without getting into the lives lost in all the conflicts.
King Leopold II really kicked off the scramble for Africa when he saw the [del]loot[/del] commercial potential of the geographic area now referred to as The Congo; the irony is that even though we think of Colonialism and Imperialism as largely being “British”, the fact of the matter was that King Leopold started it all (Il faut á la Belgique une colonie; “Belgium Must Have A Colony!”) and without his (ultimately successful) efforts to bring most of Central Africa under his control, the other Major Powers (England, France, and later Germany) would have been quite content to confine their activities to trading posts, small protectorates, naval bases, and trade “understandings” (sometimes arrived at via gunboat diplomacy) with local chiefs.
FWIW, I agree the British Empire ended in 1997 when Hong Kong was handed back; the remaning [del]colonies[/del] Overseas Territories are comparatively insignificant places like Gibraltar, Pitcairn Island, Tristan Da Cunha, St. Helena, and the (uninhabited because the previous tenants were forcibly removed) British Indian Ocean Territory. You’ve also got Gibraltar and a few islands in the Caribbean, Bermuda, and the Falkland Islands. Nothing that could be considered an “Empire”, at any rate.
Have a read of Simon Winchester’s Outposts: Journeys to the Surviving Relics of the British Empire for some idea of what the remaining parts of the British Empire are like nowadays (or about 10 years ago, when the book was last updated). Interesting stuff. King Leopold’s Ghost by Adam Hochschild also comes highly recommended and is very readable as well, FWIW.