How do you compose a song?
It really depends on the person I think. Some people come up with a melody first, some people a line. Generally it's the chorus that comes first and then you build from that other times it's just a random line and people will build around it. It just really depends on how you work best and how you work creatively as a person.
Many times, the song title is decided upon first. When you know what the song is called, it's easier to stay on subject.
Some songwriters may write the melody first, some start with the lyrics. There is no right or wrong way.
One of the most important things to consider is the structure of the song. All modern commercial songs contain some or all of the following elements: Verse, chorus, bridge and hook.
The Verse is the section of the song that tells most of the story. Each verse will have basically the same melody, but different lyrics. It builds toward and leads into the chorus.
The Chorus is the part that everybody remembers about a song. It usually contains the hook and the title, and is repeated several times throughout the song. When you hear the chorus, you know exactly what the song is about.
The Bridge or "middle eight" should be completely different, both musically and lyrically, from the verse and chorus.
Not all songs have or need a bridge. But when written effectively, a bridge provides the opportunity to add another angle to the story. You can change perspective from first-person to second or third-person if you wish. You can also change from present-tense to past or future-tense.
The Hook is the strongest line of lyric sung over the strongest line of melody. It is usually in the chorus, is nearly always the title, and is always the most memorable part of the song. It's the part that gets stuck in your head whether you like the song or not!
It's in the way these elements are arranged that determine song structure.
You generally have either a tune or lyrics, sometimes both, rolling around in you head. You find a blank music composition sheet, usually obtained at a music store that sells sheet music, sit in front of a piano and start putting the notes that you think are in your head onto the composition sheet. Otherwise, you need to be very gifted like Ludwig van Beethoven.
Techniaclly: Learn at least basic music technicals and how to read/play sheet music/tabs/your own system. Excell at your instrument/meduim. Practice, screw around, and experiment.
A more artsy answer:
Music can be created purely on a basis of musical theory or by pure expression, but mostly by combination of the two. Basic music can be created quickly with knowledge of just a few chords and scale structures, but more complex compositions might require studying theory, harmony and notation. However, theory is not completely necessary in developing music, especially in modern music. Many people learn music by ear, and use what they've heard to create new melodies.
To begin writing something, it's best to have some sort of artistic idea of what the song means, and some inspiration. Fool around with melodic ideas in your head, once you find something that sounds like a melody, use your musical knowledge to build on it.
Another aproach is to just sit down and say " I'm going to write something in G major, with a i iv v progression (as a random example.) Once you have a chord progression, you can build a melody, whether it's vocal, instruental or improvised. (improvisation is a whole other story).
Melody always comes first. Harmony is a consequence of melody. It can be proved over and over again just by simply listening within your own head. There are certain natural relationships that preside in all styles and eras of music that are constants simply from the tendency of the natural resolutions. The consistent characteristic of melodic ideas tends to capture a listener's attention and are said to possess a melodic presence. Any melody that has presence will be a melody that the ear can understand meaning that a musical person can sing, hear and remember the melodic ideas. Your ear does not hear harmony first without aurally understanding how melody works.
You do not sit down and say you are going to write something in G major with a I - IV - V progression because you are deceiving yourself. It is through melody that your ear understands the natural harmony that goes with it. Melodies were constructed first with the beginnings of humankind and still remain the first step in a successful composition. Natural resolution tendencies are described in the cycle of fifths or fourths with the tritone of the 4th and 7th degrees of a major scale. These scale degrees along with the 3rd and tonic resolutions dictate harmony. In other words, the 4th degree resolves to the 3rd degree and the 7th degree resolves to the tonic. After knowing the variety of natural relationships and substitutes in the correct order, than it becomes a matter of substitution of choice as to which of 70 plus harmonic ideas you would like to imply that would relate to the home base key. The melody still remains no matter what.