Three-axis gravity stabilization of 3U CubeSat is achieved due to selection of the nanosatellite moments of inertia at the design stage, as well as special modes included in the algorithm to provide stabilization of CubeSat relative to each motion channel separately. In this paper, we propose a modified algorithm based on the magnetic stabilization algorithm B-dot. The modified algorithm provides three modes intended to damp the initial angular velocity to the value of the orbital angular velocity, to keep the angular velocity at a value close to that of the orbital angular velocity, and to provide the nanosatellite gravitational triaxial stabilization by using one magnetic coil located on the axis with the transversal moment of inertia, which is possible due to the small angle between the magnetic field line and the satellite's trajectory. We propose two modifications for forming a control loop for orientation and stabilization of the 3U CubeSat: the first one uses measurements from magnetometers and angular rate sensors as feedback, and the second one, only magnetometers. The efficiency of the two modifications of modifications was studied by means of statistical modeling.