SLAM stands for Simultaneous Localisation and Mapping. There are a number of open sourced packages that attack this problem pretty well. The 3 main SLAM packages out there are Gmapping, Cartographer and Slam Toolbox.
The following is a list of gifs recorded. They showcase the mapping process for a medium sized map. The gifs have been sped up.