His or Her Majesty's Ship, abbreviated HMS, is the ship prefix used for ships of the navy in some monarchies. Derived terms such as "HMAS" and equivalents in other languages such as "SMS" are used.
In the British Royal Navy, the prefix was originally always quoted in full; the first recorded use of the abbreviated form, "HMS", was in 1789 in respect of HMS Phoenix. Formerly, HBMS (for His or Her Britannic Majesty's Ship) was also used.
Submarines in Her Majesty's service also use the prefix HMS, standing for "Her Majesty's Submarine". The Royal Yacht Britannia, which was a commissioned ship in the Royal Navy, was known as HMY Britannia. Otherwise all ships in the Royal Navy are known as HM Ships, though formerly when a distinction was made between three-masted ship-rigged ships and smaller vessels they would be called HM Frigate X, or HM Sloop Y.
The prefix "HMS" is also used by shore establishments that are commissioned "stone frigates" in the Royal Navy. Examples include HMS Excellent, which is a training school located on an island in Portsmouth Harbour, and HMS Vulcan, in Caithness in the Highland area of Scotland, which is established to test the design of nuclear power systems for use in submarines.
The sample ship name used by the Royal Navy to signify a hypothetical vessel is HMS Nonsuch. This is a name that has been used by the Royal Navy in the past; on the eve of World War II the name was given to the Royal Canadian Navy. HMCS Nonsuch is at present the "stone frigate" of the Edmonton Division of the Canadian Naval Reserve.
Prefixing the name by "the", such as "the HMS Ark Royal", while common, is considered bad grammar. 
British government ships not in the Royal Navy have other designations, such as "RFA" for ships in the Royal Fleet Auxiliary.
Historically, variants on "HMS" have been used by the navies of British colonies. The practice is maintained in several Commonwealth realms (states which recognise Queen Elizabeth II as their head of state).
Seiner Majestät Schiff (pronounced [ˈzaɪ̯nɐ majɛsˈtɛːt ʃɪf]; German: "His Majesty's Ship", abbreviated to S.M.S. or SMS) was the ship prefix used by the Prussian Maritime Enterprise (Seehandlung), the Prussian Navy, the Imperial German Navy (Kaiserliche Marine) and the Austro-Hungarian Navy. It was created by translating the British prefix into German.
It was sometimes also abbreviated to S.M. or SM (for Seiner Majestät) when a ship was mentioned by class, such as S.M. Kleiner Kreuzer Emden ("His Majesty's Light Cruiser Emden").
Special forms included
Abroad, Swedish navy ships are sometimes given the prefix HSwMS (for His Swedish Majesty's Ship), to avoid confusion with other uses of the HMS prefix.