i know this is a stupid question.... some songs i like all the notes fit perfectly together. i mean what exactly do you do it?
Use your ears, your knowledge, your playing skills, and your creativity. There is no 1 correct answer to this.
in basic terms, you just try various things on the guitar until you find something you like. then you repeat it until you can remember it. then you try to come up with more parts that fit in with your first part. the rest is up to you. you can have as many parts as you want, or it can just be one or two.

"but how do i know what notes will work?"

you learn theory. there's dozens of articles on this site that explain it. read this one:


i wrote it (shameless self-promotion, i know), and it will dispell all the stuff you are worried about with theory, and will show you the most basic concepts in simple terms.

there's no shortcut, magic trick, or secret fast-track technique... it's just a matter of how well you can understand the concepts of theory, and how well you can express them on guitar. you can use your ear and nothing else if you want... but learning theory just eliminates guesswork and brings logic to everything.
some people just pick a scale and go on from there, its a easy way but can be very limiting
Write a melody. Your song will be remembered by the melody, it's by far the most important part of any song.

Write an accompaniment to that melody.
[U]        | |                     [/U]
[U]        |/     .-.              [/U]
[U]       /|_     `-’       |      [/U]
[U]      //| \      |       |      [/U]
[U]     | \|_ |     |     .-|      [/U]
      *-|-*    (_)     `-’
^You could that the other way round, a la improvisation-backing-track style

You have to start a song somewhere, the melody, accompaniement, harmony, selecting each instrument, selecting form, or style or genre, whatever...

Then it goes into adding ideas, and shaping them, removing what you don't want, or fixing it, and adding new embelishments (sp?) , ornamental notes, or sections to make it more subtle, whatever...

It is very broad, it is like asking "how do I paint a portrait?"