You just need to use wp_list_categories function with param show_count set to true
https://developer.wordpress.org/reference/functions/wp_list_categories/
wp_list_categories( array(
'show_count' => true,
'title_li' => '<h2>' . __( 'Categories', 'textdomain' ) . '</h2>') );