Quarter is one of those seafaring terms that makes just about everyone think of pirates. The black, in some cases red, flag means no quarter will be given. We know that means, in turn, that resistance is futile and you might just as well lay your arms down now, mate. We will kill you. But where does that usage of a word that originally meant one fourth come from? I'm so pleased that you asked.
In sailor terms quarter originally meant the literal aft 1/4th of a ship. This morphed into the far more technical 45 degrees abaft the beam some time in the 17th century. Essentially anything behind the mizzen mast of a man of war is in the quarter. Thus the quarterdeck, the raised area, usually where the ship's wheel, bell and her main binnacle are found. By the 18th century the quarterdeck was the exclusive domain of officers and anyone coming aboard ship was expected to solute the quarterdeck.
Quarters means not just where seaman sleep but divisional batteries as well. Beating to quarters, usually with drums, indicated a ship making ready for battle with all hands hurrying to their stations. Close quarters indicates a boarding situation with either your men boarding the enemy ship or the other way round.
Quarter is applied to more than one petty officer. A ship's quartermaster is the master's mate who takes up an oversight position similar to the bosun. He is often in charge of stores and how a ship's hold is packed so that she runs at her best speed. He also oversees the order on the quarterdeck. A quarter-gunner is the gunner's mate who keeps guns and tackle in working order.
Finally, the reason we apply the term quarter to mercy may come from the Spanish. It became their habit to parole captured naval officers for one quarter of the man's yearly pay. Once quarter was given in ransom, the officer was free to return home. The ransom amount didn't necessarily apply everywhere but the term stuck. Quarter is given; you are free to go with your lives. We'll take your cargo though, jack. Just business you understand.