X-ray diffraction is a phenomenon that stems from the interaction of the electron density of a crystalline material and the electric field of the X-ray waves. The product of this interaction, the diffraction pattern, provides a picture of the reciprocal space of the atomic distribution in terms of intensities of certain scattering wavevectors. In this manner, a correlation between those intensities seen in a diffraction pattern and the electronic properties of a material is suggested. This correlation, if it exists, may not be directly proposed using analytical expressions. This article shows for the first time the feasibility of assessing the band gap of metal–organic frameworks (MOFs) and organic and inorganic materials from their X-ray powder diffraction pattern. The band gaps were assessed with convolutional neural networks (CNNs). These CNNs were developed using simulated X-ray powder diffraction patterns and the band gaps calculated with density functional theory. The diffraction patterns were simulated with different crystal sizes, from 10 nm to the macrocrystalline size. In addition, the reported band gaps of MOFs and organic compounds in the Quantum MOF Database and the Organic Materials Database data sets were used, which were calculated with the PBE functional. Furthermore, the band gaps calculated by Kim et al. [Sci. Data (2020), 7, 387] for inorganic compounds with the HSE functional were used. The developed CNNs were tested with simulated diffraction patterns of compounds different from those used to train the CNNs, as well as with experimentally recorded diffraction patterns. The developed CNNs allowed the assessment of the band gap of the compounds with a root-mean-square error as low as 0.492 eV after training with over 64 000 diffraction patterns.