https://en.wikipedia.org/wiki/Defence_mechanisms
A defence mechanism is an unconscious psychological mechanism that reduces anxiety arising from unacceptable or potentially harmful stimuli.[1]
Defence mechanisms may result in healthy or unhealthy consequences depending on the circumstances and frequency with which the mechanism is used. In psychoanalytic theory, defence mechanisms (German: Abwehrmechanismen) are psychological strategies brought into play by the unconscious mind to manipulate, deny, or distort reality in order to defend against feelings of anxiety and unacceptable impulses and to maintain one's self-schema or other schemas. These processes that manipulate, deny, or distort reality may include the following: repression, or the burying of a painful feeling or thought from one's awareness even though it may resurface in a symbolic form; identification, incorporating an object or thought into oneself; and rationalization, the justification of one's behaviour and motivations by substituting "good" acceptable reasons for the actual motivations. In psychoanalytic theory, repression is considered as the basis for other defence mechanisms.
Healthy persons normally use different defences throughout life. An ego defence mechanism becomes pathological only when its persistent use leads to maladaptive behaviour such that the physical or mental health of the individual is adversely affected. Among the purposes of ego defence mechanisms is to protect the mind/self/ego from anxiety or social sanctions or to provide a refuge from a situation with which one cannot currently cope