In this paper, we consider a variable order time subdiffusion equation. A Crank-Nicolson type compact finite difference scheme with second order temporal accuracy and fourth order spatial accuracy is presented. The stability and convergence of the scheme are strictly proved by using the discrete energy method. Finally, some numerical examples are provided, the results confirm the theoretical analysis and demonstrate the effectiveness of the compact difference method.