Sublimation: redirecting or acting out unacceptable impulses and destructive behaviors (such as addictions) in a more positive behavior or in a more socially acceptable way. In psychology, sublimation is a mature type of Ego Defense Mechanism where socially unacceptable impulses or idealizations are unconsciously transformed into socially acceptable actions or positive behavior, possibly resulting in a long-term conversion of the negative initial impulses.
Though sublimation works at a subconscious level, we can become more conscious by choosing to observe our thoughts and work towards controlling our negative impulses and re-directing them into something positive, which is an action of Transmutation. In the way that, whenever we are faced with a negative emotion, we must try and channel it into a positive action.
Sublimation is similar to Displacement, but takes place when we manage to displace our unacceptable or negative emotions into behaviors which are constructive and socially acceptable, rather than acting out destructive activities.
How Does it Work?
So how does sublimation work? We are all faced with negative emotions like anger, anxiety, frustrations, and even sexual impulses from one point of time to the other, but, because we are a part of society, we cannot impulsively act on all of these urges, no matter how strong, right, or urgent they may be. For example, just because a person angers me, I cannot go ahead and slap him. So what do I do? I go for a run and expend all that negative energy into this physical activity. In that way, my pent up frustration and anger is channeled into a more positive outlet. And that is exactly what sublimation involves―channeling and re-directing the energy generated from a negative emotion, that can, and will, cause potential self-harm, to a more positive outlet that will lead to self-improvement and personal growth.
It may not always be possible to decipher and read when this ego mechanism is at play because it is happening at a subconscious level; moreover, there may or may not be a direct correlation between the emotion that causes the sensation of negativity, and the positive action that is taken up as a result. For example, a boy who is dealing with a broken friendship may take to writing. Thus, the negative emotions of sadness and mistrust are channeled into churning out great literary work. 
Ego Defense Mechanism
As one learns how to refocus one’s thoughts, one prevents overwhelming states of emotion from triggering impulsive behaviors and angry reactions. As one develops strong impulse control they are learning a form of ego discipline through applied patience. If we check in and find that we do not like what we may be feeling, we can learn better the reasons for that by further shifting into the observer mode. In our community, we call that process of observing as shifting from identifying with a thought or feeling by moving ourselves into the compassionate witness. As a Compassionate Witness we have no judgment of thoughts or feelings, we hold no judgment of what we are observing in the external, we only observe those thoughts and feelings in our self and others. When we can fully observe through our own Compassionate Witness, we then become neutral and centered. Then, we can immediately find relief from our inner anxiety, fears and a host of other thought distortions. This process is key to shifting Ego Defense Mechanisms, thought addiction tendency and releasing the anxiety or fear of feeling emotional depth or pain. By continually using an ego defense mechanism to avoid facing the source causation of the anxiety or deeply rooted fear, (which is unresolved pain or trauma) we are only perpetuating the mental looping which uses denial of the truth in order to avoid feeling pain or discomfort. 
Sexual Sublimation, also known as sexual transmutation, is the act, especially among some religious traditions, to transform sexual impulses or "sexual energy" into creative energy. In this context, sublimation is the transference of sexual energy, or libido, into a physical act or a different emotion in order to avoid confrontation with the sexual urge, which is itself contrary to the individual's belief or ascribed religious belief. It is based on the idea that "sexual energy" can be used to create a spiritual nature which in turn can create more sensual works, instead of one's sexuality being unleashed "raw." The classical example in Western religions is clerical celibacy.
Hasidic Jewish mysticism views sublimation of the animal soul as an essential task in life, wherein the goal is to transform animalistic and earthy cravings for physical pleasure into holy desires to connect with God.
Different schools of thought describe general sexual urges as carriers of spiritual essence, and have the varied names of vital energy, vital winds (prana), spiritual energy, ojas, shakti, tummo, or Kundalini. It is also believed that undergoing sexual sublimation can facilitate a mystical Awakening in an individual.