This document presents an analytical solution for determining the optimal pumping rate in pipe networks supplied by groundwater wells. The solution is based on maximizing economic benefit from the produced water. It utilizes a case study of a pipe network supplied by two wells connected to an elevated tank and distribution pipes. Cost functions are developed that consider pipe network costs, pumping and pump costs, well and tank costs, and operation and maintenance costs. An optimization technique called the gradient method is applied to these cost functions to derive an analytical solution for optimal pumping rate. The solution is verified against graphical solutions and prior studies on the example pipe network, demonstrating the reliability of the analytical approach.