We present a study of large-scale bars in field and cluster environments out to redshifts of ~0.8 using a final sample of 945 moderately inclined disk galaxies drawn from the EDisCS project. We characterize bars and their host galaxies and look for relations between the presence of a bar and the properties of the underlying disk. We investigate whether the fraction and properties of bars in clusters are different from their counterparts in the field. The total optical bar fraction in the redshift range z=0.4-0.8 (median z=0.60), averaged over the entire sample, is 25% (20% for strong bars). For the cluster and field subsamples, we measure bar fractions of 24% and 29%, respectively. We find that bars in clusters are on average longer than in the field and preferentially found close to the cluster center, where the bar fraction is somewhat higher (~31%) than at larger distances (~18%). These findings however rely on a relatively small subsample and might be affected by small number statistics. In agreement with local studies, we find that disk-dominated galaxies have a higher optical bar fraction (~45%) than bulge-dominated galaxies (~15%). This result is based on Hubble types and effective radii and does not change with redshift. The latter finding implies that bar formation or dissolution is strongly connected to the emergence of the morphological structure of a disk and is typically accompanied by a transition in the Hubble type. (abridged)