Cells continually have to sense their environments to make decisions—to stay put or move, to differentiate or proliferate, or even to live or die. However, they are thwarted by noise at the cellular scale. Cells use signaling networks to filter this noise as much as possible and sense accurately. To operate these networks, resources are required: time, protein copies, and energy. We present a theory for the optimal design of cellular sensing systems that maximize sensing precision given these resources. It reveals a new design principle, namely that of optimal resource allocation. It describes how these resources must be allocated so that none are wasted. We show that the chemotaxis network of Escherichia coli obeys this principle.