A dog does not bite out of nowhere. It works its way up a set of signals first, and most of them are so quiet that people walk straight past them. The idea comes from Kendal Shepherd, a veterinary behaviorist, who drew it as a ladder in the BSAVA Manual of Canine and Feline Behavioral Medicine. Every rung is the dog trying to get the same thing, which is space, or an end to whatever is happening to it.
These are the ladder's own words. The notes under some of them are from the ASPCA's guide to canine body language, which describes what the rung looks like on a real dog.
The lower rungs work when the person or the other animal backs off. If they do not work, the dog stops using them. Shepherd puts it in one sentence.
Appeasement behavior is the bottom of the ladder. The socially expected outcome is space. A dog whose looking away, turning away and walking away never get it anything learns that the polite rungs are useless, and starts higher up next time.
The growl is the last rung before teeth. WVS Academy, whose page on the ladder is adapted from the BSAVA with permission, makes the point that punishing the lower level signals, the growl among them, teaches the dog to leave them out, so the next time it goes straight to the bite with no apparent warning. A dog that growls is still telling you. A dog that has been taught not to growl is not.
Stop what you are doing and give the dog room. That is the whole of it. The dog is asking for the situation to end, and the fastest way down the ladder is for the asking to work. If a child is involved, move the child, not the dog.
If a dog is reaching the top rungs with people or other animals more than once, that is a conversation with a vet, and the vet may point you to a behaviorist. It is not something to train out of a dog on your own, and the ladder explains why: the training that suppresses the warning is the training that removes it.
The calm, playful and worried signals that come before these, with a one-page sheet to print, are on the dog body language page.