The cockroach's thorax consists of three segments ; prothorax, mesothorax and metathorax. Each thoracic segment bears a pair of walking legs.
The prothoracic legs are closest to the it's head. These are the shortest legs, and they act like brakes when the cockroach runs.
The middle legs are the mesothoracic legs. They move back and forth to either speed the cockroach up or slow it down.
The very long metathoracic legs are it's back legs, and they move it forward.
A typical cockroach legs consists of 5 different segments namely coxa, trochanter (acts like a knee), femur and tibia (resemble thigh and shin bones) and tarsus as shown in the diagram.