600798 Disclosed is a system (1) for sorting livestock, in particular cattle, from a grazing area to a milking area. The system has a sorting compartment (40) surrounded by delimitations, an access port (3) to the sorting compartment (40) and two or more exit ports (14a-14d) from the sorting compartment (40), and at least one movable sorting wall. The access port (3) and the exit ports (14a-14d) each have at least one gate leaf which is movable between a closed position and one or more pass positions. First counting means are used for ascertaining a passage of an animal through the access port (3) and second, third or more counting means for ascertaining a passage of an animal through a respective exit port (14a-14d). The counting means are operatively connected to a programmable control unit (15). The system is also provided with first closing means for holding the access port (3) in a closed position. The system further comprises drive means for moving the sorting wall from a position steering the livestock from the access port to a first exit port to a position steering the livestock from the access port to a second exit port, and the control unit is configured for activating the drive means for the sorting wall on the basis of a comparison of the data from the second counting means with the data from the first counting means.