Cartesian grid with cut-cell method has drawn attention of CFD researchers owing to its simplicity. However, it suffers from the accuracy near the boundary of objects especially when applied to viscous flow analysis. Hybrid grid consisting of Cartesian grid in the background, body-fitted layer near the object, and transition layer connecting the two is an interesting alternative. In this paper, we propose a robust method to generate hybrid grid in two-dimensional (2D) and three-dimensional (3D) space for viscous flow analysis. In the first step, body-fitted layer made of quadrangles (in 2D) or prisms (in 3D) is created near the object's boundary by extruding front nodes with a speed function depending on the minimum normal curvature obtained by quadric surface fitting. To solve global interferences effectively, a level set method is used to find candidates of colliding cells. Then, axis-aligned Cartesian grid (quadtree in 2D or octree in 3D) is filled in the rest of the domain. Finally, the gap between body-fitted layer and Cartesian grid is connected by transition layer composed of triangles (in 2D) or tetrahedrons (in 3D). Mesh in transition layer is initially generated by constrained Delaunay triangulation from sampled points based on size function and is further optimized to provide smooth connection. Our approach to automatic hybrid grid generation has been tested with many models including complex geometry and multi-body cases, showing robust results in reasonable time. Copyright (c) 2012 John Wiley & Sons, Ltd.