Device-to-device (D2D) communication is one of the most promising technologies in wireless cellular networks that can be employed to improve spectral and energy efficiency, increase data rates, and reduce links latency. This paper investigates fifth generation and beyond (5GB) networks, the basics of D2D communication, applications, and classification. Herein, D2D in in-band (IBD) and out-band (OBD) modes are discussed. This paper also presents the integration of D2D communication with other prominent technologies and demonstrates the importance of integration with possible solutions in improving network performance. We further investigate the challenges of D2D communication, opportunities, and future research directions of D2D in 5GB networks. In addition, D2D communication in 6G network challenges and open research areas are introduced.INDEX TERMS 5G, 5GB, 6G, D2D communication, millimeter wave (mm-Wave), visible light communication (VLC), ultra-dense network (UDN), and unmanned aerial vehicle (UAV).