Orders of precedence in the United Kingdom

The order of precedence in the United Kingdom is the sequential hierarchy for Peers of the Realm, officers of state, senior members of the clergy, holders of the various Orders of Chivalry and other persons in the three legal jurisdictions within the United Kingdom:
Separate orders exist for males and females.
Determination of precedence.
The order of precedence is determined by various methods. The Precedence Act (which technically applies only to determine seating in the House of Lords Chamber) and the Acts of Union with Scotland and Ireland generally set precedence for members of the nobility. The statutes of the various Orders of Chivalry set precedence for their members. In other cases, precedence may be decided by the sovereign's order, by a Royal Warrant of Precedence, by letters patent, by Acts of Parliament, or by custom.
Source of precedence.
One may acquire precedence for various reasons. Firstly, one may be an office-holder. Secondly, one may be of a particular degree such as duke. Thirdly, in the case of women, one may be the wife of a title-holder (note that wives acquire precedence due to their husbands, but husbands do not gain any special precedence due to their wives). Finally, one may be the son or daughter of a title-holder. 
One does not gain precedence as a child of a lady, unless that lady is a peeress in her own right. Furthermore, if a daughter of a peer marries a commoner, then she retains her precedence as a daughter of a peer. However, if she marries a peer, then her precedence is based on her husband's status, and not on her father's.
British royal family.
The King or Queen of the United Kingdom, as the sovereign, is always first in the order of precedence. A king is followed by his queen consort, the first in the order of precedence for women. The reverse, however, is not always true for queens regnant. There is no established law of precedence for a prince consort, so he is usually specially granted precedence above all other males by letters patent or, on the other hand, may rank lower than the heir apparent or the heir presumptive, even if the heir is his own son.
Officers of State.
In England and Wales, the Archbishop of Canterbury is the highest in precedence following the royal family. Then come, assuming the post of Lord High Steward is vacant (as it usually has been since 1421), the Lord Chancellor, the Archbishop of York and the Archbishop of Wales. Next come the Prime Minister, the Lord President of the Privy Council, the Speaker of the House of Commons, the Lord Speaker of the House of Lords (since July 2006), the President of the Supreme Court of the United Kingdom (since October 2009), the Lord Chief Justice of England and Wales (since November 2007) and the Lord Privy Seal.
The precedence of the Lord Great Chamberlain, the Earl Marshal, the Lord Steward and the Lord Chamberlain are determined by the rank and class of the peerage of the holders of such offices.
In Scotland, the Keeper of the Great Seal of Scotland and the Keeper of the Privy Seal of Scotland, if Peers, rank after the Lord Speaker of the House of Lords. If not so, then they rank after the younger sons of dukes. The Hereditary High Constable of Scotland and the Master of the Household in Scotland rank above dukes. If the Keepers of the Seals are Peers, then the Keepers precede the High Constable and Master.
Peers of the Realm.
The ranks of Peers are as follows: Duke (and Duchess), Marquess (and Marchioness), Earl (and Countess), Viscount (and Viscountess), and Baron (and Baroness) together with Scottish Lord (and Lady) of Parliament.
Within their own respective ranks, the rank of Peers correspond to the venerability (age) of the creation of their peerages, but the Peerage of England (pre-1707) takes precedence over the Peerage of Scotland (pre-1707), together taking precedence over the Peerage of Great Britain (1707–1801), together over the Pre-Union Peerage of Ireland (pre-1801), and together they all take precedence over either the senior Peerage of the United Kingdom (post-1801), or the junior Post-Union Peerage of Ireland (1801–1922).
Subject to the same governing rules as detailed in the paragraphs above, the rank of the wives of Peers is also governed by the venerability (age) of the peerage. A dowager Peeress (widow of a deceased Peer) would however always precede the wife of the present Peer.
Barons and Baronesses of the life peerage rank immediately below Barons and Baronesses of the hereditary peerage and Scottish Lords and Ladies in Parliament.
Primates, archbishops, bishops, Scottish Lord High Commissioners and moderators.
In England and Wales, the Archbishop of Canterbury, Primate of All England, is the most senior person outside of Royalty, and after the Lord Chancellor, immediately followed by the Archbishop of York, Primate of England, and immediately followed by the Archbishop of Wales. Primates, archbishops and bishops of the Church of England in England and the Church in Wales rank immediately above Peers. First come the Bishops of London and Durham, followed by the Bishop of Winchester, followed by the other diocesan bishops in order of seniority, and then the suffragan bishops in order of seniority.
The Bishop of Sodor and Man and the Anglican Bishop of Gibraltar in Europe, whose "Sees" are full and integral parts of the Ecclesiastical Provinces of York and Canterbury, respectively, are also usually included as suffragan bishops of the Church of England for the purpose of precedence.
See the list of Lords Spiritual for the most senior 21 diocesan bishops ordered by seniority.
In Scotland, the Lord High Commissioner to the General Assembly of the Church of Scotland ranks immediately below the sovereign or consort (depending on their respective sex), but only when the General Assembly is in session, and immediately followed by the Moderator of the General Assembly of the Church of Scotland.
According to the "unofficial" order of precedence for Northern Ireland published by the publishers of "Burke's Peerage", 106th Edition, , the precedence of "all" of the primates and archbishops of the Roman Catholic Church in Ireland and the Church of Ireland, together with the Moderator of the Presbyterian Church in Ireland, are to be determined solely by seniority, according to the dates of consecration or translation, or the date of election, in the case of the Presbyterian Moderator, without any presumption of automatic Roman Catholic or Protestant seniority, Anglican or Presbyterian.
Baronets, knights and holders of state honours.
The two highest orders of chivalry in England and Wales, and in Scotland, are the Orders of the Garter, and the Thistle, respectively. Knights of the Order of the Garter precede baronets. After the baronets come the members of all the other orders of chivalry in the following order of their ranks: Knight or Dame Grand Cross, Knight or Dame Commander, Commander or Companion, Lieutenant or Officer, and Member. 
For individual members with equivalent ranks but of different orders, precedence is accorded based on the seniority of the orders of chivalry: the Order of the Bath, the Order of St Michael and St George, the Royal Victorian Order, and the Order of the British Empire. For equivalent ranks and orders, those appointed earlier precede those appointed later. Knights Bachelor come after Knights Commander of the Order of the British Empire.
Wives of Knights of the Garter, Knights of the Thistle, Knights Grand Cross, Knights Commanders, and Commanders or Companions receive precedence based on their husbands' positions. Wives of individuals of a certain rank follow in precedence after female holders of the same rank. Thus, wives of Knights Grand Cross follow Dames Grand Cross.
Wives of baronets go immediately above all Dames Grand Cross, but are below (though not immediately below) Ladies and Wives of Knights of the Garter, the Thistle, and St Patrick. Baronets' widows follow rules similar to dowager peeresses; a widow of a previous baronet comes immediately before the wife of the present baronet.