Cocaine can stay in your system for several days at a minimum; the metabolites of cocaine, or the substances that your body produces in response to the introduction of cocaine, can remain in you much longer. Most modern drug tests can detect not only the cocaine itself, but the metabolites, and so drug use should be stopped long before any drug testing is begun.
If you have only used cocaine once—ever—the cocaine itself will be mostly gone from your body after three days. Trace amounts might be left, however, depending on how your body metabolizes the drug, your body size, your sex, and the amount of cocaine you ingested. The metabolites your body produces from the cocaine will remain for up to several weeks.
If you’re a habitual cocaine user, though, all bets are off. The cocaine has metabolized itself into your blood, urine, internal organs and even your hair. It takes much, much longer for all the metabolites to leave your system, and the drug tests test for not only the drug itself, but the metabolites.