To work under contract, you sign a contract, and, as a result, you are a contractor, a subcontractor, or a principal contractor.
Company P hires a contractor C. Then, C contracts out the job (or part of it) to Company D.
P is a principal to C.
C is P's principal contractor.
D is a subcontractor to P.
C is a principal to D.
C is both contractor and principal at the same time: P > C > D