Today's AC railway feeding systems are composed by several conductors with various connections to each other. The return current is shared between rails, ground wires connected to rails, ground; current flows to ground are determined by rail-to-ground distributed conductance. This paper gives formulas to deal with all these complexities, both for power quality and power frequency studies, integrating and combining previous studies which cover only part of them.Especially new in this paper is a technique to include in the computation currents dispersed into soil through ballast.It also illustrates a way to implement easily all the proposed formulas using a specific, open and flexible simulation language, the Modelica language. An application of the proposed formulas and related simplifications is illustrated.