Military standards
There are set situation and rules for the salute:
The military hand salute is a 'movement' of respect stemming back to medieval days [and before]. When two armored and helmeted men would meet, they would lift their visors so that both parties could see each other's faces and show that their right hand [usually the sword hand] did not carry a weapon.
You can see the same sort of action in Ancient Rome with the fist to chest - it shows the man facing you is unarmed - no sword or knife in his hand.
Most salutes also require the 'greeting of the day' to be given, at least, when out doors [sometimes in - military protocol]. This is usually something like "Good Morning, Sir."
All enlisted of no matter what rank salute an officer of any rank, the enlisted instigating the salute and the officer returning it. The enlisted is to maintain the hand salute and not drop it until it is returned by the officer. The salute offered indoors is a matter of company police [some don't *require* the use of the hand salute indoors but it's use is optional and can sometimes help get you out of trouble if you've mucked up. This can be discussed later].
Junior officers are required to salute a senior ranking officer, even if they are only separated by one pay grade. A Captain salutes a Major, a Colonel salutes a General. A Lieutenant salutes everybody.
Enlisted do not usually salute enlisted except under very certain situations, such as unit /platoon /company /etc formations when the presiding officer has released the officers and remanded the enlisted members to the senior NCO present. When the SNCOP releases the enlisted to their individual NCO's, those NCOs receiving their troops salute the SNCOP who returns their salute.
Unless an area is designated a 'no cover' area [you don't have to wear a hat or 'cover' outside a building], you salute while wearing headgear. The exceptions are: women are allowed to wear a head covering indoors and do not require a salute and :a person bearing arms [weapons] is always wearing a cover [check out the SF's: if they've got a sidearm, they've got a hat] and do not require a salute indoors.
If a member of the military is out of uniform at a military function such as a funeral or the passing of the US flag on parade, a salute is not appropriate. The placing of
of one's right hand over the heart is the appropriate gesture of respect.
One situation where saluting is *not welcome* is in a combat environment. One of the reason the different branches of the service have gone to subdued colors for rank insignia. In passing, you may make a quiet recognition, but do nothing that may signal out who is senior and/or who is in command.
Or, as I had to teach my officer Nurses in Desert Storm: 'Sniper Check, Ma'am. They shoot the one who salutes second.' [the officer is the one who returns the salute. You might as well just ,ark them with bright orange paint.]
I think this covers the basic. Any specific questions, please feel free to ask. I gotta do something with all this stuff the Army taught me and I taught my junior NCOs and enlisted.