Mudflats and sandflats are two common types of coastal tidal flats, the structure and function differences of microbial communities between them are still underappreciated. Beibu Gulf is a diurnal tidal regime located in China, the differences between the two type of tidal flats could be more distinct. In this study, we collected a total of 6 samples from Beibu Gulf, consisting of 3 sandflats samples and 3 mudflats samples, classified based on clay and silt content. Generally, the mudflats samples exhibited higher levels of NH4+_N and TOC, but lower in ORP and pH. The microbial diversity of the two types of tidal flats was investigated, revealing great differences existed and sandflats had higher microbial richness and diversity than mudflats. Furthermore, we analyzed the association between microbial communities and environmental factors, finding NH4+_N to have the highest contribution to the total variation in microbial community structure, and microbial groups such as Desulfobacterota, Campilobacterota, Chloroflexota, Calditrichota, Spirochaetota, Zixibacteria, Latescibacterota and Sva0485 group in mudflats were positively associated with NH4+_N. The functions of microbial community were predicted using metagenomic sequences and metagenome assembled genome (MAG). Mudflats contained more genes for carbon fixation. Nitrate and nitrite reduction were widely existed in mudflats and sandflats, but nitrogen fixation was only existed in mudflats, and Campilobacterota, Desulfobacterota and Gammaproteobacteria MAGs were mainly responsible for it. Sandflats composed more genes for ammonium oxidation, but no MAG was found whether in sandflats or mudflats. Microbes in mudflats exhibited a greater abundance of genes related to sulfur cycling, especially in reduction process, unique MAGs in mudflats such as Calditrichota, Chloroflexota, Desulfobacterota and Zixibacteria MAGs are responsible for sulfate and sulfite reduction. Finally, we predicted functions of ammonium related microbes in mudflats based on MAGs and found Campilobacterota and Desulfobacterota MAGs were important for high accumulation of ammonium in mudflats. This study illuminated the structural and functional differences of microbial communities in mudflats and sandflats, providing new insights into the relationship of microbial communities and environment in the tidal flat.