The origin of this practice can be as far back as 1912, when British Ship, Heart Ease captain died on a voyage to Canada. The ship came back to London flying its flag at a half mast as a way of honoring the dead captain.
According to one claim by scholars, lowering the Union Jack was the sailor's way of making room for the unseen flag of death. This agrees with the practice in Britain where the half-staff flag is flown at 1 flag width below its usual position to show that the flag of death flaps above it.
The flag flies at half-mast on certain days like September 11 every year-to mark the terror attack on the pentagon and the World Trade Center, May 15 to mark the peace officers day, December 7, to mark the Pearl Harbor Memorial. On every Memorial Day, the flag flies at half-staff from morning until noon, by noon it is raised back to full mast.
Amazingly, it doesn't stop at raising it to half-mast on the pole, whenever a flag flies at half-mast, it is a sign of deep mourning, in which the flag is quickly lifted to full mast before being lowered to half-mast position.
In the U.S, the death of any principal officer of the United States government attracts a presidential order for the flag to be flown at half-mast, as a mark of respect to the fallen patriot. Once such an order has been issued, every government building, public schools, offices, and military barracks are expected to fly the national flag at half-mast. According to the federal law, no other flag whether state, city, local, or society flag is expected to fly above the national flag. So every other flag must fly at half-mast the moment the national flag has been lowered to half-mast. However, no penalty exists for failing to abide by this rule in order not to violate the first amendment.