Here's how I do it:
1. I first write in the treble and the bass clefs with the accolade (a brace which joins several staves).
2. Then I decide what the key of the melody is going to be and write in the necessary accidentals next to the key.
3. After the accidentals have been written in, it's time to choose the meter and notate the meter signature at the beginning of each stave.
4. Decide how many measures will your melody have and cross all necessary bar lines leaving some adequate space for the notes (usually 4 measures in one system). A period (one complete musical idea) often has 8 measures but the numbers might vary quite a bit.
5. After that you are ready to write in the soprano line - your melody with the stems up in the upper stave. If you are the beginner, use only the notes of the scale without any additional accidentals. If you know what you're doing, alterations and chromaticisms will spice up the color quite a bit.
One of the easiest ways to create a melody is to use question/answer approach. Measures 1-4 start on the tonic note and end on a different note (that's the question). Measures 5-8 can repeat the rhythms and even the melodic contour of the question but will end on the tonic note.
6. This step is crucial - you will create a smooth bass line moving in every beat with the stems down in the lower stave. Use the notes of the 3 main chords (T, S, D) that go with each beat in the soprano line. Aim for the contrary motion with the melody as much as possible. This will help you avoid unwanted parallel 5ths and 8ves.
7. If you wrote your melody in various rhythms, feel free to leave out any non-chordal notes that can go without their own chords.
8. Supply the missing middle parts - alto and tenor. Alto part - with the stems down in the upper stave and the tenor - with the stems up in the lower stave.
9. As you are writing in the alto and tenor, think about the T, S, D notes. In root position chords double the root, in the 1st inversion - the root or the 5th, and in the 2nd inversion - the 5th. If you use 7th chords and their inversions, no doubling is necessary (except for the 7th chord which can have a double root without the 5th).
Try this approach and you'll be creating and harmonizing your melodies and tunes in no time.
[HT to Mindaugas]