diff --git a/extmod/moductypes.c b/extmod/moductypes.c
index 6e4a94b606762d35d8ae194d8da11fe94bf2a1b6..48cbfad52d217762f8b2b1596384b11745de5393 100644
--- a/extmod/moductypes.c
+++ b/extmod/moductypes.c
@@ -230,6 +230,9 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_
                 mp_uint_t offset = MP_OBJ_SMALL_INT_VALUE(v);
                 mp_uint_t val_type = GET_TYPE(offset, VAL_TYPE_BITS);
                 offset &= VALUE_MASK(VAL_TYPE_BITS);
+                if (val_type >= BFUINT8 && val_type <= BFINT32) {
+                    offset &= (1 << OFFSET_BITS) - 1;
+                }
                 mp_uint_t s = uctypes_struct_scalar_size(val_type);
                 if (s > *max_field_size) {
                     *max_field_size = s;
diff --git a/tests/extmod/uctypes_sizeof.py b/tests/extmod/uctypes_sizeof.py
index 93de2abb088be84b1ac1a97fcb298a3832e4e442..fcfd8ecd748dd76832e5790504b4f1a860cac920 100644
--- a/tests/extmod/uctypes_sizeof.py
+++ b/tests/extmod/uctypes_sizeof.py
@@ -6,7 +6,11 @@ desc = {
     # arr2 is array at offset 0, size 2, of structures defined recursively
     "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
     "arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
-    "arr4": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0, "w": uctypes.UINT16 | 1})
+    "arr4": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0, "w": uctypes.UINT16 | 1}),
+    "sub": (0, {
+        'b1': uctypes.BFUINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+        'b2': uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+    }),
 }
 
 data = bytearray(b"01234567")
@@ -29,3 +33,6 @@ except TypeError:
 print(uctypes.sizeof(S.arr4))
 assert uctypes.sizeof(S.arr4) == 6
 
+print(uctypes.sizeof(S.sub))
+assert uctypes.sizeof(S.sub) == 1
+
diff --git a/tests/extmod/uctypes_sizeof.py.exp b/tests/extmod/uctypes_sizeof.py.exp
index b0e3a0ac6bc958bb0591e1d409f682e895c1e728..fb74def602b9735418a9aaeae4b75f428617a78d 100644
--- a/tests/extmod/uctypes_sizeof.py.exp
+++ b/tests/extmod/uctypes_sizeof.py.exp
@@ -3,3 +3,4 @@
 4
 TypeError
 6
+1