Using Blender 3.5. I am modelling this rook chess piece and having some weird shading issues. Here, in the image, the place where the rook's top wall and window meet, I have the shading problem. I applied a bevel and subdivision surface modifier on it. How can I fix this?
Changing the topology as you suggested didn't completely solve the issue but gave me the idea of getting acquainted with topology in general. It seems like there was a pole on that corner where 5 edges meet. I turned it to a vertex where only 4 edges meet.
The problem isn't how many faces you have meeting there, it's that you're generating non-convex polygons. Subdividing an N-gon with a concavity results in... well, the mess you discovered.
That said, you probably don't want 'Sharp' outer miters, especially if you're going to try to subdivide the result further. So, first change that to 'Arc' (as in John's answer). I'd also play around with the width type; I've noticed 'Absolute' often gives more consistent results.
The way (I found) to fix this with the least modeling changes is to split the faces to either side of the crenels (below the merlons) into triangles with the diagonals pointing to the corners. This happens to work with two subdivisions of bevel (and outer miter set to 'Arc'!) because it results in convex quads around the problem corners:
(You may notice I also added a ring of quads to the top. This significantly improved some artifacts that were popping up there.)
Applying subdivision gives this result:
FWIW, I'd also recommend removing the 'baked in' bevels and instead generating them with a modifier. Use bevel weight to achieve different bevel radii.
BTW, I'd be darned tempted to model this as a revolute and use boolean operations to cut the crenels. That would probably allow you to avoid needing subdivisions at all. (Or, model it in FreeCAD so you can model it as surfaces rather than polygons.)