Porous electrodes are an integral part of many electrochemical devices since they have high porosity to maximize electrochemical transport and high surface area to maximize activity. Traditional porous electrode materials are typically homogeneous, stochastic collections of small scale particles and offer few opportunities to engineer higher performance. Fortunately, recent breakthroughs in advanced and additive manufacturing are yielding new methods to structure and pattern porous electrodes across length scales. These architected electrodes are emerging as a promising new technology to continue to drive improvement; however, it is still unclear which structures to employ and few tools are available to guide their design. In this work we address this gap by applying topology optimization to the design of porous electrodes. We demonstrate our framework on two applications: a porous electrode driving a steady Faradaic reaction and a transiently operated electrode in a supercapacitor. We present computationally designed electrodes that minimize energy losses in a half-cell. For low conductivity materials, the optimization algorithm creates electrode designs with a hierarchy of length scales. Further, the designed electrodes are found to outperform undesigned, homogeneous electrodes. Finally, we present three-dimensional porous electrode designs. We thus establish a topology optimization framework for designing porous electrodes.