Allah prescribed the prayer through the tongue of your Prophet as four units while resident, two units while traveling, and one unit during times of fear.
فرض الله الصلاة على لسان نبيكم في الحضر أربعا، وفي السفر ركعتين، وفي الخوف ركعة.
Muslim narrated it in the Book of the Traveler's Prayer (687) through several chains from Abu Awana, from Bukayr bin Akhnas, from Mujahid, from Ibn Abbas, and he mentioned it. In another narration, "Allah has enjoined the prayer on the tongue of your Prophet, for the traveler two rakats, for the resident four, and in fear one rakat."As for His saying, "If you fear that those who disbelieve may harm you" [Nisa 4:101], this reflects the predominant case, otherwise shortening the prayer is permissible in a state of security just as it is permissible in a state of fear, and that is why this matter caused confusion for some of the companions.