Metagenomics, the genomic analysis of microbial communities directly from environmental samples, has revolutionized our understanding of microbial ecology and the functional capabilities of complex ecosystems. This culture-independent method accesses genetic information from entire microbial communities, including unculturable organisms that represent the majority of microbial diversity. By extracting and sequencing total DNA from environmental samples, metagenomics provides insights into community composition, metabolic potential and ecological interactions. High-throughput sequencing technologies have greatly enhanced these analyses, allowing exploration across diverse habitats, from the human gut to deep-sea vents. Approaches include targeted sequencing of phylogenetic marker genes or whole-genome shotgun sequencing. Despite computational challenges, advanced bioinformatic tools enable the assembly, annotation and comparison of sequences, facilitating the reconstruction of microbial genomes and the identification of novel genes and pathways. Comparative metagenomics has led to crucial discoveries in environmental science and human health. Ongoing advancements, such as single-cell genomics and long-read sequencing, address current challenges, promising deeper insights into microbial diversity and function for applications in medicine, biotechnology, and environmental management.