Swern oxidation is one of the selective methods for oxidizing primary alcohols to aldehydes.
Like other mild oxidizing agents, such as pyridinium chlorochromate (PCC), pyridinium dichromate (PDC), and the Dess-Martin (DMP) oxidation, it stops the oxidation once the carbonyl group is formed. And if it is a primary alcohol, the product is an aldehyde, while the oxidation of a secondary alcohol results in a ketone.
Tertiary alcohols cannot be oxidized by Swern or by any other technique.
Here is a general scheme of the alcohol oxidation patterns depending on the nature of the oxidizing agent, and this is covered in a lot more detail in this post: Oxidation of Alcohols.

For now, let’s focus on the Swern oxidation. First, what reagents are used here?
Dimethyl sulfoxide (DMSO) and oxalyl chloride (COCl)2 are used as oxidizing agents in the Swern oxidation:

The Mechanism of Swern Oxidation
There are quite a few reagents used for the oxidation of alcohols, but the good news is that most of them follow a similar mechanism, and we will try to identify a common trend for these reactions.
The idea here is to install a leaving group on the hydroxyl oxygen and remove the neighboring hydrogen by kicking out the leaving group to form a c=O π bond. It should remind you of the E2 mechanism:

Notice the importance of the ɑ-hydrogen in the elimination step. It is the removal of this hydrogen that provides the electron to form the C=O π bond.
The Mechanism of Swern Oxidation
In the first step of Swern oxidation, DMSO and oxalyl chloride react to form a chlorodimethylsulfonium salt, which is a Lewis acid and reacts with the alcohol, thus installing the good leaving group necessary for the elimination step:

The E2 elimination can be achieved by amines as organic bases, and triethylamine (TEA) is used most often for this purpose.

