Is there a formula or method of planning a flexible homebrew campaign or session?

When ever I’m planning a session for my campaign I tend to plan a very strict plot. It makes me feel comfortable, and though you can never feel ready; it makes me feel ready to play when I have a plan.

If the players go off of the plot it really messes me up.

Is there a specific planning process or formula that most DMs use in planning a session? Put another way: is there a way to plan a session, that is flexible to what the players do.

Is there a formula (or something similar) that most DMs use?