The handkerchief code (also known as the hanky code, the bandana code, and flagging) is a color-coded system, employed usually among the gay male casual-sex seekers or BDSM practitioners in the leather subculture in the United States, Canada, and Europe, to indicate preferred sexual fetishes, what kind of sex they are seeking, and whether they are a top/dominant or bottom/submissive. The hanky code was widely used in the 1970s by gay and bisexual men, and grew from there to include all genders and orientations.
Today, wearing color-coded handkerchiefs (bandanas), usually in the back pocket or around the belt loop, is the manner in which communication of desires and fetishes is achieved.
Wearing a handkerchief on the left side of the body typically indicates one is a "top" (one considered active in the practice of the fetish indicated by the color of the handkerchief), while wearing it on the right side of the body would indicate one is a "bottom" (one considered passive in the practice of the fetish indicated by the color of the handkerchief). This left-right reality is taken from the earlier practice of tops wearing their keys on the left belt loop and bottoms on the right to indicate being a member of the leather subculture.
In the past bandanas might be worn tied around the neck (with the knot positioned on either the left or right side); around the ankle (when wearing boots or when undressed); or on other parts of the body.
There is no universally understood color code, and regional codes vary widely. There is general agreement upon the colors for more common practices, particularly those with an intuitive relation between the color and the practice, such as yellow for urolagnia; brown for coprophilia; and black for SM, but no absolute consensus for less common practices.

Worn on left Color Worn on right
Loves to masturbate   White   Loves stroking
Heavy S&M Master   Black   Heavy S&M Slave
Actually own A Suit   Charcoal   Likes in suits
Bondage top   Grey   Bondage bottom
Latex Fetish, top   Charcoal   Latex Fetish, bottom
Pisser   Yellow   Piss freak
Scat top   Brown   Scat bottom
Spits   Pale yellow   Loves to be spit on
Has 8" or more   Mustard   Wants a big one
Couple looking for third   Gold   Looks for a couple
Anything, anytime, anywhere   Orange   Anything, but not now
"Two Tons of Fun"   Coral   Chubby chaser
Loves his toes sucked   Coral   Loves sucking toes
A Cowboy   Rust   Horse
Spanker   Fuchsia   Spankee
Dildo Fucker   Light pink   Dildo Fuckee
Tit Torturer   Dark pink   Tit Torturee
Likes to pierce   Violet purple   Likes to get pierced
Fist Fucker   Red   Fist Fuckee
2-handed Fister   Dark red   2-handed Fistee
Wants head   Light blue   Expert cocksucker
Fucker   Navy blue   Fuckee
Cop   Dark blue   Cop-Sucker
Cock&Balls torturer   Teal blue   Cock&Balls torturee
Hustler   Green   John
Military Top/Officer   Olive green   Military Bottom/recruit
Daddy   Hunter green   Hunting for daddy