Chief Keef turned himself in to Cook County authorities today after testing positive for marijuana ... and was sentenced to serve 20 days in jail.
Keef -- real name Keith Cozart -- was ordered to undergo random drug testing as part of his probation, stemming from a speeding ticket he got back in May in Chicago, when cops clocked him going 110mph in a 55mph zone.
Keef pled guilty to the ticket, but apparently didn't hold up his end of the no-drugs bargain ... so now he's stuck behind bars.
The rapper posted the above pic to his Instagram a couple hours ago, along with the caption ... "Outside The Court House Turnin My Self In 😤😣 But F*** It I Got N****s Facin More Then That ! For Sh*t Like killin Police officers."
Keepin' it classy.
FYI, it's unlikely Keef will serve all 20 days ... we're told the rapper expects to get out by tomorrow due to overcrowding. Calls to his reps weren't returned.