Natural terrain is uneven so it may be beneficial to grasp onto the depressions or ‘valleys’ between obstacles when walking over such a surface. To examine how leg geometry influences walking across obstacles with valleys, we (1) modeled the performance of a two-linkage leg with parallel axis ‘hip’ and ‘knee’ joints to determine how relative segment lengths influence stepping across rocks of varying diameter, and (2) measured the walking limbs in two species of intertidal crabs, Hemigrapsus nudus and Pachygrapsus crassipes, which live on rocky shores and granular terrains. We idealized uneven terrains as adjacent rigid hemispherical ‘rocks’ with valleys between them and calculated kinematic factors such as workspace, limb angles with respect to the ground, and body configurations needed to step over rocks. We first find that the simulated foot tip radius relative to the rock radius is limited by friction and material failure. To enable force closure for grasping, and assuming that friction coefficients above 0.5 are unrealistic, the foot tip radius must be at least 10 times smaller than that of the rocks. However, ratios above 15 are at risk of fracture. Second, we find the theoretical optimal leg geometry for robots is, with the distal segment 0.63 of the total length, which enables the traversal of rocks with a diameter that is 37% of the total leg length. Surprisingly, the intertidal crabs’ walking limbs cluster around the same limb ratio of 0.63, showing deviations for limbs less specialized for walking. Our results can be applied broadly when designing segment lengths and foot shapes for legged robots on uneven terrain, as demonstrated here using a hexapod crab-inspired robot. Furthermore, these findings can inform our understanding of the evolutionary patterns in leg anatomy associated with adapting to rocky terrain.