Traditionally, 3DES is configured in a mode called EDE, which means "Encrypt, Decrypt, Encrypt". This means that your encryption operation looks like this: $c = E(D(E(m, k_1), k_2), k_3)$. As it turns out, if all three subkeys are independent, the security of the system is not impacted by the second operation being a decryption.
The reason for this construction is a historic one. When 3DES was being introduced, people wanted a way to fall back to a "legacy" mode which amounted to just plain DES. This is handled through keying modes, of which there are three:
- Keying mode 1: All three subkeys are independent (which implies probabilistic inequality, though some implementations may enforce $k_1 \neq k_2 \neq k_3$ explicitly)
- Keying mode 2: $k_1$ and $k_2$ are independent, but $k_1 = k_3$.
- Keying mode 3: All three subkeys are equal, i.e.e $k_1 = k_2 = k_3$.
In keying mode 1, you get full 3DES with a 168-bit key (3 × 56-bit). In keying mode 2, you get a 112-bit version of 3DES (2 × 56-bit), though this keying mode is less commonly used in practice. In keying mode 3, the first two steps cancel out, leaving you with just DES:
$$\require{cancel}\cancel{a = E(m, k)}$$
$$\cancel{b = D(a, k)}$$
$$c = E(b, k)$$