There are different kinds of "flags". And their usage varied over time. The posts above covered "class" flags pretty well. White for extras and green for advanced sections of regular trains. Red flags occasionally got used as markers, although I have an old NWP rule book that shows green flags used as markers. Herders who controlled the switches into and out of yards used green flags and perhaps red flags to let trains know if it was safe to proceed. "Flagmen" who protected the rear of stopped trains from following trains used red flags. Green, red and yellow "flags" are also used along the track to govern speed through slow orders and maintenance work. These flags are now typically metal signs, but the fact they are called flags suggests to me the were actual flags back in the old days...but that's just a guess on my part. And there are probably other uses that I can't think of.