Windows 11 is not a complete rewrite.
It builds on Windows 10 (first released in 2015), which was based on Windows 8.x, which was based on Windows 7 (2009), which was based on Windows Vista (2007), which was based on Windows XP (2001). Windows XP was based on Windows NT. NT was first released in 1993; its development started from scratch at Microsoft in 1988.
Windows NT has been the basis for all versions of Windows Server since 1993, all desktop versions from Windows XP (2001) onward, all operating system products with “NT” in the name, and all operating system products with 2000 in the name.
In each major release, some parts of the operating system have been refactored and/or redesigned, and features have been added of course, but the vast majority of code is the same between one release and the next.