Jacob is right that you need to incorporate the function of paginate_links() but I would suggest looking at the examples on this page:
https://developer.wordpress.org/reference/functions/get_the_posts_pagination/
My Theme (the amazing MHMagazine Theme) has this function built in and this is how they do it (it does exactly as OP wants, a few digits, an ellipsis, a few more digits, and right or left arrows as needed):
if (!function_exists('mh_magazine_pagination')) {
function mh_magazine_pagination() {
if (get_the_posts_pagination()) {
echo '<div class="mh-loop-pagination clearfix">';
the_posts_pagination(array(
'mid_size' => 1,
'prev_text' => esc_html__('«', 'mh-magazine'),
'next_text' => esc_html__('»', 'mh-magazine'),
));
echo '</div>';
}
}
}
You can see an example of this in action at this page (scroll to bottom):
https://www.bestallinclusive.com/category/insider-tips/
(Mods, it's okay to delete that last link if not allowed, but I think this does exactly what OP wants so thought he'd like to see it to be sure before trying to implement this).