The force balance over a control volume in a pipe can be used to derive the head loss due to friction in a pipe. In this case we only have only one direction x and the pipe element is not moving. The video shows the derivation of the frictional losses in the pipe section based on the force balance for an ideal fluid with a viscosity:
The fanning friction factor has a complex relationship which depends on the Reynold's number and the dimensionless surface roughness of the pipe, i.e. the pipe material. The video below shows how we calculate the fanning friction factor for a given fluid system:
The interactive graph below is the Moody chart.