We prove that in every finitely generated profinite group, every subgroup of finite index is open; this implies that the topology on such groups is determined by the algebraic structure. This is deduced from the main result about finite groups: let w be a ‘locally finite’ group word and d ∈ N. Then there exists f = f (w, d) such that in every d-generator finite group G, every element of the verbal subgroup w(G) is equal to a product of f w-values.