Is there a formula or method of planning a flexible campaign or session? [duplicate]


When ever I’m planning a session for my campaign; I tend to plan a very strict plot. And if the players go off of it; it really messes me up. I was wandering if there was a specific planning process or formula that most DMs use in planning a session. It makes me feel comfortable, and though you can never feel ready; it makes me feel ready to play when I have a plan. However, is there a way to plan a session, that is flexible to what the players do. Like a formula or something that most DMs use?