Music theory

How to Write a Melody

Rhythm first on one note, then pitches from the scale: move by steps, leap once, high note in the second half, end on the root. Written for a piano roll.

Start with rhythm on a single note, then add pitch using the scale you are already in. Move mostly by steps, leap once, put the highest note in the second half, and end on the root. That is the whole method, and it can be done in a piano roll tonight with a plain synth sound and no ability to read music. By the end of this page you will have written a four-bar melody that works, and you will know what to change when it works but does not interest you.

This is a shape, not a formula for a hit. Every melody you like breaks one of these rules somewhere. But the rules are what the ones you like are breaking, and you need the shape before you can bend it.

The short answer

A melody is a rhythm and a set of pitches, and beginners get stuck because they try to choose both at once. Choose the rhythm first, on one note. Then give each note a pitch from the scale, mostly one step away from the note before it. Build it as two phrases: the first ends somewhere unresolved, the second ends on the root. Put the single highest note in the second phrase. Repeat more than you think you should.

A four-bar melody in a piano roll with scale rows highlighted: a two-bar question ending on 5, a two-bar answer with one high note that ends on the root

EDM Tips describes a melody as exactly these two parts: “Rhythm (the pattern in which the notes are played)” and “Pitch (the different pitches of each of those notes)”. Everything below is a way of deciding one, then the other.

Start with rhythm, not notes

Draw the rhythm of the melody in the piano roll on one note, the root of your key, before you move anything up or down. If it does not work as a rhythm it will not work as a melody, and it is far easier to hear a rhythm when every note is the same pitch.

The producer guides agree on this step. EDM Tips’ guide for producers: “Lay down the rhythm of your melody using the root note of your scale. Focus solely on rhythm to ensure it interacts well with the bass and chords.” Loopcloud’s melody techniques frame it as a cure for being stuck: “Choose a note that’s in key with your song and program a rhythm that works within the context of the track using only that note. Once you’ve landed on something that you like, go through the phrase and move each note up or down to create a melody.”

In the piano roll, that means: set a four-bar loop at your track’s tempo, pick the root, and draw notes on it. Use eighth notes and quarter notes. Leave gaps. A rhythm with no rests is a drone with pitches, and rests are what make the rhythm a rhythm. Four to six notes per bar is a good density to start; a melody with sixteen notes a bar is a riff, and a different job.

Two things to try before you move on. Line some of the notes up with the kick, and put others in the gaps between kicks, so the melody sits both on and off the beat. And make bar 4 different from bar 3, so the loop has an ending. EDM Tips calls this the flourish added “to let the listener know that a particular phrase is coming to an end”. If you have no drums to write against yet, How to Make Beats on GarageBand gets you a pattern in ten minutes.

The rhythm of the melody drawn on the root note across four bars, with the kick pattern underneath showing which notes land on and off the beat

Let the scale do the safety work

Turn on the piano roll’s scale highlighting for the key your track is in, and only place notes on the highlighted rows. Every note you choose will fit. Now the only decision left is which of seven notes, not which of twelve.

Number the scale degrees 1 to 7 from the root. The root, 1, is home. The fifth, 5, is the strongest note that is not home. The third, 3, is what makes the key sound major or minor. Those three, 1, 3 and 5, are the notes of the key’s home chord, and a melody that lands on them on the strong beats will always sound like it belongs. EDM Tips sorts the degrees the same way: “Root Note: Establishes a strong sense of the track’s key. Third and Fifth Intervals: Add emotional weight and harmony.” The other four, 2, 4, 6 and 7, are the notes you pass through on the way.

If the melody sits over a chord progression, the same idea applies chord by chord: Loopcloud notes that “the root and fifth note of any chord are always the strongest and most distinctive to use.” Landing on a chord tone on the downbeat of each bar is the simplest way to make a melody sound written rather than found. Music Theory for Producers covers the scales and chords this sits on top of; you need one scale and one chord to write your first melody, not the whole page.

How a melody moves: steps, leaps and where to put the one big jump

Move mostly by step, one scale degree at a time, and leap once. Then step back the other way. A melody that is all steps wanders; a melody that is all leaps sounds like a bassline. The balance is roughly two steps for every leap.

Loopcloud gives the ratio: “it’s a good idea to have about half to two-thirds of your melody made up of steps, and one-third to half made up of skips or leaps.” A step is the next scale degree up or down. A skip jumps one degree, 1 to 3. Anything larger is a leap. Loopcloud’s reason for saving them: “Stepwise motion makes a melody easy to sing along to”, and large leaps “should be saved for dramatic, high-impact moments when you want to excite the listener.”

After a leap, come back by step in the opposite direction. This rule is old enough to have a name in counterpoint textbooks, and Open Music Theory’s chapter on species counterpoint states it in one line: “any large leaps (fourth or larger) are followed by step in opposite direction.” Ableton’s Making Music, written for producers, says the same: “Commonly, a melody that has moved by leap will then move by step in the opposite direction.” A leap opens a gap; the ear wants it filled.

In degrees, a phrase might run 1, 2, 3, 2, 1, then leap 1 to 5, then 4, 3. The leap is the moment. The steps back are what make it a moment rather than a jolt.

Question and answer: the two-phrase shape

Write the four bars as two phrases of two bars. The first phrase ends on a note that is not the root, so it sounds like a question. The second uses the same rhythm, or nearly, and ends on the root, so it sounds like the answer.

In the piano roll: bars 1 and 2 are the question, ending on 5 or 2 or 7, anything with tension. Bars 3 and 4 copy the rhythm of bars 1 and 2, change a few pitches, and land on 1 on the last note. The rhythm being the same is what makes the two halves sound like a pair; the ending being different is what makes the second one an answer.

MusicRadar’s Computer Music team describes the same structure as A, A, B, C: a motif, the motif again, a variation, and a resolution. Their example is a Dua Lipa melody where a descending run “is repeated over four two-bar sections, but the third section is inverted so that it runs back up the scale”. Copy, copy, change, resolve.

If you want the question-and-answer idea across two instruments rather than one, EDM Tips calls it call and response: “simply split the melody across two different instruments, and have them alternate, to simulate them ‘speaking’ to each other.” A lead asks, a second synth an octave up answers.

Where the high note goes

Put the highest note of the melody in the second half, use it once, and leap up to it. A melody with one clear peak has a shape; a melody that hits its top note in bar 1 and again in bar 3 has nowhere to go.

Open Music Theory lists this among the properties of every well-formed melody it teaches from: “a single climax (high point) that usually appears only once in the melody”, with a “smooth shape from beginning to climax to ending”. Its rule for placing it: “Aim for exactly one unique climax in each melodic part. Avoid ending on that climax. Preferably leap to that climax.” Making Music gives the producer’s version: “Good melodies often have a single peak note. That is, the highest pitch in the melody occurs only once. Furthermore, that peak note often (although certainly not always) occurs on a ‘strong’ beat.”

So the leap from the previous section and the high note from this one are usually the same event. Somewhere in bar 3, leap up to the top note of the melody, on a downbeat or the beat after it, then step down toward the root for the ending. The music theorist David Huron, quoted on the same Open Music Theory page, calls this the melodic arch: “The tendency for melodies to ascend in the first half of a phrase, reach a climax, and descend in the second half.”

Keep the whole melody inside an octave, or a little more. A melody that spans two octaves is a synth line for a machine, not a tune a person can hold in their head.

The melody drawn as a contour by scale degree: stepwise motion, one leap to a single peak in bar 3, a step back, and a descent to the root

What to do when it still sounds boring

If the melody follows every rule above and still does nothing, the problem is almost always one of three things: not enough repetition, not enough rests, or a rhythm that never changes. Fix those before you touch the pitches.

Repeat more. Four different bars feel like more work than four the same, and the instinct is wrong. Computer Music: “Like it or not, repetition is a vital ingredient in music, especially pop”, and the aim of repeating “is to fix the tune firmly in your listener’s ear, so that they both expect it when it happens again, and remember it once it’s over.” EDM Tips: “The more repetition you’ve got in terms of pitch and of rhythm, the more memorable that melody is going to be.” Repeat bars 1 and 2 exactly, then change one thing in bar 4.

Take notes out. A melody is a rhythm as much as a pitch set, and rests are part of the rhythm. Delete every second note in bar 2 and listen again. Loopcloud’s test for a melody: “Take a five minute break from what you’re doing and leave the room – the one that you can remember at the end of the break is the one to go with!”

Vary the rhythm before the pitches. Loopcloud: “Rhythmic interest makes things less predictable and is also a useful tool for directing the energy of a track.” Push one note late by an eighth, or hold one for twice as long, and the same pitches become a different melody.

A 2017 study of earworms agrees with the shape above. Jakubowski and colleagues, analysing 100 tunes that 3,000 people named as earworms against 100 matched tunes nobody named, found the sticky ones “have more common global melodic contours” and “less common average gradients between melodic turning points”, at faster tempos. The APA’s summary of the paper translates that: a “fairly generic and easy-to-remember melody but with some particular intervals, such as leaps or repetitions that set them apart”. The rise-then-fall contour is the common part. The one leap is the particular part.

The half nobody mentions: the sound

The same notes on a different sound are a different melody. Write the melody on a plain sawtooth with the filter half open, and once the notes work, the sound is where the next hour goes.

EDM Tips gives the reason to write on a plain patch first: “If your melody sounds good even with a crappy sound, you’re onto a winner and can then choose a better sound later on.” The reverse is also true, and it is the trap. A rich preset makes a weak melody sound finished and hides what is wrong with it. Write on the boring sound, fix the notes, then change the sound and hear the melody again as if someone else wrote it.

Then the choices are the synth’s, not the piano roll’s. A pluck with a fast envelope makes the rests audible, because every note stops before the next one. A pad with a slow attack blurs the rhythm and turns the same line into a wash, which is sometimes what you want. Detune the oscillators and the line widens; close the filter and the leap to the high note loses its brightness and needs a filter envelope to get it back. Everything about how the melody feels, as opposed to what its notes are, lives in the four moves of sound design, and they are a different evening.

Common questions

What are the rules for writing melody?

Rhythm first, on one note. Pitches from the scale, mostly by step, landing on chord tones on the strong beats. One leap, followed by a step back. Two phrases, the first unresolved, the second ending on the root. One high note, in the second half, used once. Repeat more than feels comfortable. None of these is a law; every one is a default, and the melodies you like are the ones that know which default they are breaking.

How do I compose a melody?

Set a four-bar loop, draw a rhythm on the root, then move each note onto a scale degree so that the line moves by step, leaps once to its highest note in bar 3, and ends on the root in bar 4. Play it on a plain sound. Change one thing at a time until it stays in your head after you leave the room.

How do I make a catchy melody?

Repeat, keep the shape simple, and put one unusual thing in it. The earworm study above found the tunes people cannot shake have common overall contours, rise then fall, with one unusual interval or repetition in them. A catchy melody is mostly expected and slightly not.

What is the 80/20 rule in songwriting?

It means two different things depending on who says it. Most often it is the Pareto principle applied to output: songwriting coaches use it to mean that “If you write 100 songs, only 20 will likely do anything”. The melodic version belongs to the songwriting teacher Gary Ewer, who proposed that a song should be “doing something somewhat predictable at least 80% of the time”, with “no more than 20% of your song being innovative and unexpected.” That is a good description of the melody this page builds: four bars of expected, one leap of not.

One evening

Rhythm, scale, steps, one leap, two phrases, one peak, the root. That is a melody, and it takes an evening. Detune’s Music Theory path has a module on melody and phrases that teaches this shape by ear, without notation, on the same synth the sound-design lessons use. The notes are the fast half. The sound is the one that takes practice.