For even cycles, Bondy and Simonovits proved in the 1970s that ex(n,C2ℓ)=O(n1+1/ℓ), and this bound is conjectured to be sharp up to the implicit constant. In this paper we prove that the number of C2ℓ-free graphs on n vertices is at most 2O(n1+1/ℓ), confirming a conjecture of Erdős. Our proof uses the hypergraph container method, which was developed recently (and independently) by Balogh, Morris and Samotij, and by Saxton and Thomason, together with a new ‘balanced supersaturation theorem’ for even cycles. We moreover show that there are at least 2(1+c)ex(n,C6)C6-free graphs with n vertices for some c>0 and infinitely many values of n∈N, disproving a well-known and natural conjecture. As a further application of our method, we essentially resolve the so-called Turán problem on the Erdős–Rényi random graph G(n,p) for both even cycles and complete bipartite graphs.