I do it in a few ways.
For example, sometimes I just need to sit down and carefully write a skeleton of my composition, and other times the music comes by itself (usually when I am falling asleep haha) that's why I always have pen and paper prepared and I slowly collect all my ideas, and then later on play around them and I do lot of thinking. But I like to (and I really try hard to do that) imagine the whole piece all together (the goal, the vision) and later on, I am figuring out the details and how to reach my (hopefully) original vision. Then it seems much easier to write it as a whole. The process of envisioning is harder.