A backflow preventer allows water to flow only in one direction within the pipe. Each backflow preventer has a one-way valve (a check valve) that doesn't allow water to go back into the supply line. It opens when the water is going in the correct direction. When there is no water flowing through the valve, it closes, so the water on the other side can't go back and mix with the water in the supply line.
There are several types of check valves that backflow preventers use; the ball check valve is the most common kind. It consist of a ball that blocks the supply line and stops the water flow because its diameter is larger than that of a supply line. Another part of the valve is the spring attached to the ball, which keeps the ball in the off position. The water pressure from the supply line side forces the ball to move back and allow the water to go though the pipe.
The backflow preventer keeps the water from entering the supply line not only if there is no water flow from the line, but also when the water flows from both sides. If the water pressure from the supply line is stronger, the water goes through the valve. If the water pressure from the other side is stronger, the ball closes the opening of the supply line and doesn't allow the water to flow backward.