In this paper, we propose an optimal cooperative sensing technique for cognitive radio to maximize sensing performance based on energy detection. In most spectrum sensing research, many cooperation methods have been proposed to overcome the sensitivity of energy detection so that both primary and secondary users are better off in terms of spectral efficiency. However, without assigning a proper sensing threshold to each sensing node, cooperation may not be effective unless the received average primary user signal-to-noise ratio (SNR) is identical. We show that equal threshold energy detection severely degrades sensing performance when cooperative sensing nodes experience diverse average SNRs, and it is not unusual for even single-node sensing to be better than cooperative sensing. To this end, based on the Neyman–Pearson criterion we formulate an optimization problem to maximize sensing performance by using optimized thresholds. Since this is a non-convex optimization problem, we provide a condition that convexifies the problem and thus serves as a sufficient optimality condition. We find that, perhaps surprisingly, in all practical cases one may consider this condition satisfied, and thus optimal sensing performance can be obtained. Through extensive simulations, we demonstrate that the proposed technique achieves a globally optimal solution, i.e., it maximizes the probability of detection under practical operating parameters such as the target probability of false alarm, different SNRs, and the number of cooperative sensing nodes.