Much like modern day engineered devices, cells in the human body are able to make precise measurements: intestinal epithelial cells monitor local cell densities to prevent hyperplasia, neutrophils sample their microenvironment to compute the fastest migratory route toward infection sites, and epidermal stem cells use extracellular matrix occupancy to make cell fate decisions. What these examples illustrate is the sensitivity of complex cell behaviors to spatial and mechanical constraints, known in quantitative sciences as boundary conditions. Although the importance of boundary conditions in cell and tissue physiology is increasingly recognized, it remains unclear how cells sample their boundaries to tailor specific behaviors to boundary conditions. Here, using biophysical tools to manipulate cell boundaries in a highly controlled, quantitative manner, we found that cells estimate externally-imposed confinement using their largest and stiffest intracellular component, the nucleus. Cell confinement below a certain threshold deforms the nucleus and expands its envelope area. Unbuffered against area expansion due to slow turnover of constituents, the nuclear envelope becomes stretched. This in turn engages signaling via nuclear membrane stretch-sensitive proteins to the actomyosin cortex, activating contractility. The latter provides a motive force for the cell to squeeze through tight pores and constrictions in the extracellular matrix. Interestingly, no increase in cell contractility is observed when cells move through environmental confines that do not significantly deform the nucleus. Thus, the nucleus acts as an internal ruler for environmental confinement size, allowing cells to utilize energetically costly contractility on demand, only when surrounding space becomes restrictive. The advantage of the proposed mechanism is that in contrast to the plasma membrane, nuclear membranes do not participate in constitutive membrane trafficking; their surface area thus fluctuates less. This intrinsic quiescence should privilege them to function as low-noise detectors, to readily discriminate local environmental conditions from internal traffic-induced cell area/tension fluctuations.