Denote by [MATHEMATICAL FORMULA] the class of all triangle-free graphs on n vertices and m edges. Our main result is the following sharp threshold, which answers the question for which densities a typical triangle-free graph is bipartite. Fix 0 and let [MATHEMATICAL FORMULA]. If n/2 m (1 ) t3, then almost all graphs in [MATHEMATICAL FORMULA] are not bipartite, whereas if m (1 + )t3, then almost all of them are bipartite. For m (1 + )t3, this allows us to determine asymptotically the number of graphs in [MATHEMATICAL FORMULA]. We also obtain corresponding results for C-free graphs, for any cycle C of fixed odd length.