This paper addresses a numerical algorithm for nonlinear analysis of frames, using the unit displacement method, in generating a reduced stiffness matrix of the structure. This algorithm can properly be used in nonlinear static analysis or in the incremental response spectral method. Here, the instantaneous reduced stiffness matrix of the structure is calculated, considering its linear behavior at the latest state, by performing a set of numerical tests on the whole structure. Each numerical test consists of imposing prescribed displacement fields on the lateral displacement of stories and calculating the reactions of the structure. The solution procedure of each test is based on the division of degrees of freedom into three parts: (1) predefined lateral displacement of joints, (2) vertical displacement of joints, considered as linear degrees of freedom, and (3) rotation of joints, regarded as nonlinear degrees of freedom. The stiffness matrices are generated distinctly for all mentioned parts. Therefore, the linear stiffness matrix is inverted once at the beginning of the analysis. The suggested method is not limited to any special case or physical assumptions. This model has good accuracy in representing structural responses and modal properties, confirmed by different numerical examples. Regarding computational cost, the proposed algorithm is more efficient in comparison with the conventional method.