A tufting machine comprising: backing rollers (5, 6) to feed a backing medium through a tufting region in a tufting direction; a sliding needle bar comprising at least one row of needles and being reciprocable at the tufting region to drive the needles into and out of the backing medium, and being slideable in a direction lateral to the tufting direction; gauge parts (8, 9) on the back side of the backing medium which is opposite to the needle bar to receive loops of yarn formed by the needles; a controller which receives pattern data for a carpet to be tufted; a stitch selection mechanism operated by the controller to allow selection of a yarn of a colour required by the pattern data to form a tuft in the backing medium as it is presented by the needle bar and to prevent formation of a tuft of a colour not required by the pattern data as it is presented by the needle bar; and a yarn feed mechanism to control the feed of yarns, the amount of yarn fed to each needle being controlled by the controller to provide an amount of yarn required to form the tuft of the desired pile height, and the amount of yarn required for the back stitch; characterised by the controller being configured to determine any points of entanglement (E1, E2) between different yarns from the pattern data, a point of entanglement being defined as a point where the yarn from one needle crosses and traps the yarn from another needle on the back face of the backing medium; the controller being configured to calculate an additional length of back stitch caused by each point of entanglement by subtracting an ideal back stitch length, calculated as the path which would have been taken by the yarn had it not been entangled in another yarn, from an actual yarn path, calculated as the actual length of the entangled yarn, the controller adding to the amount of yarn fed by a respective yarn feed mechanism for each stitch an amount equivalent to the additional length of back stitch. backing rollers (5, 6) to feed a backing medium through a tufting region in a tufting direction; a sliding needle bar comprising at least one row of needles and being reciprocable at the tufting region to drive the needles into and out of the backing medium, and being slideable in a direction lateral to the tufting direction; gauge parts (8, 9) on the back side of the backing medium which is opposite to the needle bar to receive loops of yarn formed by the needles; a controller which receives pattern data for a carpet to be tufted; a stitch selection mechanism operated by the controller to allow selection of a yarn of a colour required by the pattern data to form a tuft in the backing medium as it is presented by the needle bar and to prevent formation of a tuft of a colour not required by the pattern data as it is presented by the needle bar; and a yarn feed mechanism to control the feed of yarns, the amount of yarn fed to each needle being controlled by the controller to provide an amount of yarn required to form the tuft of the desired pile height, and the amount of yarn required for the back stitch; characterised by the controller being configured to determine any points of entanglement (E1, E2) between different yarns from the pattern data, a point of entanglement being defined as a point where the yarn from one needle crosses and traps the yarn from another needle on the back face of the backing medium; the controller being configured to calculate an additional length of back stitch caused by each point of entanglement by subtracting an ideal back stitch length, calculated as the path which would have been taken by the yarn had it not been entangled in another yarn, from an actual yarn path, calculated as the actual length of the entangled yarn, the controller adding to the amount of yarn fed by a respective yarn feed mechanism for each stitch an amount equivalent to the additional length of back stitch.