diff --git a/dune/istl/matrixindexset.hh b/dune/istl/matrixindexset.hh
index acc4466b4a093ff0923042c36ef3fe08a01fa2d1..c6c60bd164a59779229da8ef12edbb61d2d6163e 100644
--- a/dune/istl/matrixindexset.hh
+++ b/dune/istl/matrixindexset.hh
@@ -31,7 +31,7 @@ namespace Dune {
    */
   class MatrixIndexSet
   {
-    using Index = std::size_t;
+    using Index = std::uint_least32_t;
 
     // A vector that partly mimics a std::set by staying
     // sorted on insert() and having unique values.
diff --git a/dune/python/istl/matrixindexset.hh b/dune/python/istl/matrixindexset.hh
index 31c4cb8c99d111f626edaad5c1f384ce3c7e9d91..ae2e26722e80671958efd0459577feb6943cb2a3 100644
--- a/dune/python/istl/matrixindexset.hh
+++ b/dune/python/istl/matrixindexset.hh
@@ -3,6 +3,7 @@
 #ifndef DUNE_PYTHON_ISTL_BCRSMATRIX_HH
 #define DUNE_PYTHON_ISTL_BCRSMATRIX_HH
 
+#include <cstdint>
 #include <memory>
 #include <stdexcept>
 #include <string>
@@ -29,7 +30,7 @@ namespace Dune
     void registerMatrixIndexSet(pybind11::handle scope,
                             pybind11::class_<MatrixIndexSet, options...> cls)
     {
-      typedef std::size_t size_type;
+      using size_type = Dune::MatrixIndexSet::size_type;
 
       // two different possible constructors
       cls.def( pybind11::init( [] () { return new MatrixIndexSet(); } ) );