Several years ago, eight to be precise, I published a page called boys training in the last half of the 19th century and the following piece I have simple copied from it and pasted it here

Naturally, one of the things the boys learnt to do from day one of their training, was to salute.  All wardroom officers were saluted which included some warrant officers.  Now I am not going to teach you to suck eggs, but I'll wager that few of you know how saluting was carried out in those days!  The proverbial RIGHT HAND salute was used exactly the same as today,  for all occasions except a couple, when sailors saluted with their LEFT HAND.  Any ideas? No, I guessed right! If an officer and a sailor were marching and approaching each other, the sailor saluted the officer with which ever hand was the furthest from the officer [the off-hand], thereby reducing the chances of hitting the officers arm on the upward movement of the arm. So, if the sailor was passing the officer right arm to right arm [opposite to the rule of the road which dictates that ships pass each other left side to left side {port to port - red to red}, the sailor uses his LEFT hand to salute.  If passing on the rule of the road side he uses his RIGHT hand; the officer always uses his right hand when being passed by all subordinates to his own rank, but applies the LEFT and RIGHT hand rule when he himself is passing an officer of superior rank. Take a look at this and in particular, saluting [REMEMBERING to use your horizontal scrollbar on BOTH thumbnails to see the full script] Click to enlarge and at the next plate which I am showing you in full to keep the context. It comes from QR and AI - Queens Regulations and Admiralty Instructions - [the 'Q' being Victoria of course] Click to enlarge. Read the whole thing if you want, but look specifically at the bottom of the page for saluting.

So, saluting was pan-navy and applied to all personnel. You have seen the acts of diffidence, namely taking off [or doffing] your cap, and this was a personal thing only which applied when appropriate.  This single act of diffidence led to a defaulter at a Captains Table being ordered to show his diffidence because he had erred.  The Captain was all important whereas the defaulter was a lowly and inconsequential person full well knowing that he was to be punished and perhaps harshly.  The practice of doffing headgear was a late Georgian thing onwards for gentlemen to do to show marks of respects to ladies and to men senior in social terms to themselves, so the naval practice was not so unusual. I remember well my grandfather and my father doffing their caps to the family doctor when meeting on the street. Officers in uniform would salute first and the return salute from a lady would be an offer of her hand to be kissed or a curtsy or a subtle nod of the head and for a man a more protracted nod of the head in recognition of respect. That leads us to the order of "off caps."

The Navy League from the days of the 19th century and very active up until the late 1950's early 1960's, was a group of naval devotees who saw it their duty that all costs the navy should always be well equipped, well provided for, and for all posterity, the senior armed service of the Crown. The Members were a mix of academics, captains of industry, judges, senior armed forces officers [army and RAF as well as navy] but above all else influential  bastions of society, culture and learning.  It was the Navy League who lobbied and more or less paid for Nelson's Column in Trafalgar Square to be erect albeit 20 odd years after the Battle of Trafalgar, and it was they who every anniversary thereafter, bedecked the base of the Column with flowers and garland.  Their base was in London in Pall Mall and in the base were solicitors, archivists, librarians and the like. Their reference library was only bettered by that in the Admiralty Building at the top end of Whitehall.

In 1953, a question was asked of the League about the naval order "off caps" and this was their reply.

From this piece we learn that the 1953 edition of QR & AI [Queens Regulations and Admiralty Instructions] had no laid down reasons for, or guidance procedures for a mass off caps order.  It had become a habit almost.  Also, the 25 years mentioned in referring to HMS Ganges was to the period 1928 and first used at pay parades.

Today, we take our caps off, or should take them off, when entering a building, somebody's home or a house of Religion, to cheer ship, when a salute is not required by an officer, when a warrant is read, at prayers, when carrying a coffin, at sporting events.

It would appear that HMS Ganges set a precedent.