Total height h = h_w + t_f. The centroid y̅ is measured downward from the top of the flange.
Left = T cross-section (red line = elastic neutral axis y̅, yellow dashed = plastic neutral axis PNA) / Right = bending stress σ = M·y / I (top = compression, bottom = tension)
A T-section is an asymmetric cross-section made of a flange b_f x t_f and a web t_w x h_w. The centroid and section properties follow from elementary mechanics of materials.
Total area and centroid y̅ (distance below the top of the flange):
$$A = b_f t_f + t_w h_w,\qquad \bar{y} = \frac{b_f t_f \cdot \tfrac{t_f}{2} + t_w h_w \cdot (t_f + \tfrac{h_w}{2})}{A}$$Moment of inertia I about the elastic neutral axis (parallel-axis theorem):
$$I = \frac{b_f t_f^3}{12} + b_f t_f\!\left(\bar{y}-\tfrac{t_f}{2}\right)^2 + \frac{t_w h_w^3}{12} + t_w h_w\!\left(t_f + \tfrac{h_w}{2} - \bar{y}\right)^2$$Section moduli (top and bottom) and the shape factor f:
$$S_\text{top} = \frac{I}{\bar{y}},\quad S_\text{bot} = \frac{I}{h - \bar{y}},\quad f = \frac{Z_p}{S_\text{min}}$$The plastic neutral axis PNA is the position that splits A/2 above and below; the plastic section modulus is Z_p = (A/2)(d_t + d_b), where d_t and d_b are the distances from the PNA to the centroids of the upper and lower halves.