Originally, British spying came under the jurisdiction of the Secret Service Bureau, a joint operation of the War Office and the Admiralty. This originally had two sections, a naval one and an army one. These would become specialised in foreign intelligence and counter-intelligence respectively. During WWI, the Secret Service Bureau was merged into the War Office's Directorate of Military Intelligence. Under the Directorate, sections were given an MI designation as an abbreviation of their official title. The full title was Military Intelligence, Department No X. These sections fulfilled the general roles of military intelligence - MI4 prepared maps, for example, while MI1 was the army's codebreaking centre.
All in all, 17 MI numbers were used. There were never 17 sections in existence at the same time - MI1 merged with the Navy's Room 40 to form GCHQ in 1919, while MI5 would form the Security Service in conjunction with Scotland Yard's Special Section in 1931. The numbers used were non-contiguous; MI13 and MI17 were never used.
Sources:
Christopher Andrew, The Defence of the Realm: The Authorised History of MI5, Allen Lane, 2009