At least the way I do it. I write down events, one after the other, until I am certain that the main story has a beginning, a middle, and an end. Subplots and character motivations spring up along the way, often, but when I sit down at the keyboard or with the pad of paper and start, new ramifications arise. A heroine starts to burble that she didn't happen into this branch of service; true, she's expected to enter some branch, and would never have been derelict in duty, but owing to having been in the right place at the right time, it was clearly her duty earlier.
Mind you, she still hasn't come clear about exactly what she was doing, and whether it's an independent story that could be written on its own or not. My characters have grown more forthcoming over the years, but that still doesn't mean they tell all.
There are people who write more organized outlines than me, but I suspect that sometimes even they get taken by surprise.