As nicely described in Wikipedia: In music, an accidental is a note whose pitch (or pitch class) is not a member of the scale or mode indicated by the most recently applied key signature.
In musical notation, the sharp (♯), flat (♭), and natural (♮) symbols, among others, are used to mark such notes, and those symbols may themselves be called accidentals. In the measure (bar) in which it appears, an accidental sign raises or lowers the immediately following note (and any repetition of it in the bar) from its normal pitch, overriding sharps or flats (or their absence) in the key signature. One occasionally sees double sharps or flats, which raise or lower the indicated note by a whole tone. Accidentals apply within the measure and octave in which they appear, unless canceled by another accidental sign, or tied into a following measure.
The modern accidental signs derive from the round and square small letter b used in Gregorian chant manuscripts to signify the two pitches of B, the only note that could be altered. The round b became the flat sign, while the square b diverged into the sharp and natural signs.