In this paper, we derive the optimal user pairing and power allocation in uplink non orthogonal multiple access (NOMA) networks. The optimal power allocation that maximizes the sum rate is found for two user NOMA networks, while ensuring that the individual rates of NOMA users are at least equal to those they would achieve with orthogonal multiple access (OMA). Next, we prove that in a 2K user network and when the optimal power allocation is used, the optimal pairing reduces to pairing the user with index k to the user with index 2K-k+1, i.e., the user with the best channel condition and the one with the worst channel condition are paired together, the second best with the second worst and so on. Finally, the expressions of the corresponding optimal NOMA power coefficients are derived analytically for networks with more than two users. With these expressions at hand, our simulation results validate the superiority of NOMA over OMA in terms of sum rates.