If doubt arises after completing the Tawaf, it is ignored, and the Tawaf is valid.
If doubt occurs during Tawaf and the exact number cannot be determined (e.g., unsure whether it is the 6th or 7th circuit), the Tawaf is generally invalid and must be performed again.
(The precise ruling depends on the opinion of one’s religious authority.)