How to Get Category count in Magento 2?

Retrieve the category count total for the store in Magento 2 using the getCount() method.

If you require the number of category count for the Magento store, You can easily fetch that info by the Magento\Catalog\Api\CategoryManagementInterface.

Create a simple Model class to retrieve the total number of category,

<?php
namespace Jesadiya\CategoryCount\Model;

use Magento\Catalog\Api\CategoryManagementInterface;

class CategoryCount
{
    /**
     * @var CategoryManagementInterface
     */
    private $categoryManagement;

    public function __construct(
        CategoryManagementInterface $categoryManagement
    ) {
        $this->categoryManagement = $categoryManagement;
    }

    /**
     * Fetch all Category count
     *
     * @return int
     */
    public function getCategoryCount()
    {
        $categoryCount = $this->categoryManagement->getCount();

        return $categoryCount;
    }
}

Call method using, $categoryCount = $this->getCategoryCount();

Output:
int