How long is an accidental valid? Does it apply to all octaves? How can you remove the impact of an accidental? This page will answer all of these questions about accidentals (and help you prevent having accidents with them!).
Accidental Valid for a Measure (Sometimes!)
When an accidental appears next to a note, it modifies all notes of the same letter name and octave until the end of the measure or until another accidental appears for the same note. In other words, an accidental applies to all notes in that measure from the accidental forward that appear on the same line or space of the staff (unless another accidental appears later in the measure).
In the example below, the D# applies to all of the D notes in the measure, even though the sharp only appears by the first D.

Once the bar line is crossed, the accidental no longer applies. In the example below, the D# applies to three eighth notes in the first measure, but no longer applies to the half note in the next measure. No marking is needed to remove the effect of the D# in this case – crossing into a new measure removes the impact of the accidental.

Applies Only to Notes Including and After Accidental
Note that the accidental only applies to notes after and including the note where the accidental appears. Any note of the same letter name and octave prior to the accidental is not impacted by the accidental.

Applies Only to Same Octave
An accidental only applies to the octave where it is written. In the example below, the D# applies to the first note and third note because they are in the same octave. Even though the sixth note is also a D and appears after the accidental, it is a D natural because it is a different octave than the one to which the accidental was originally applied.

If the upper D in this passage should be a D#, then an accidental must appear next to the upper octave D as well as the fourth line D. In the passage notated below, all Ds are D#.

Applies Until Another Accidental Overrides
When an accidental is added to a measure, it may be overridden by another accidental. In this case the same rules apply to the second accidental – it is valid until the end of the measure in the same octave (unless it is overridden by yet another accidental!). In the example below, the original D# is overridden by the D natural on the sixth note. The eighth note of the measure is also a D natural because the natural carries through to the end of the measure.
