I read somewhere that the rank of a matrix is the number of its nonzero rows or columns after Gaussian elimination. In the following matrices, how should I know Gaussian elimination is done? They are not lower or upper triangular, is the lower/upper triangular form only for square matrices? Is the following numbers correct as the rank of matrices that I calculated according to nonzero rows/columns rule?
$$ T_1= \begin{bmatrix} X & X & X & X\\ 0 & X & X & X\\ 0 & 0 & 0 & 0 \end{bmatrix} $$
Here $m<n$ and $\text{rank}(A)=2<m$
$$ T_1= \begin{bmatrix} X & X & X \\ 0 & X & X \\ 0 & 0 & 0 \\ 0 & 0& 0 \end{bmatrix} $$
Here $m>n$ and $\text{rank}(A)=2<n$
"After Gaussian elimination" implies in row echelon form.
The rank is the number of non-zero rows (or number of leading entries) in row echelon form.
E.g. highlighting the leading entries, the matrices $$ \begin{bmatrix} \color{blue}{5} & 2 & 21 & 4 \\ 0 & \color{blue}{-4} & 2 & 3 \\ 0 & 0 & 0 & 0 \\ \end{bmatrix} \text{ and } \begin{bmatrix} 0 & \color{blue}{300} & 3 & 3 \\ 0 & 0 & 0 & \color{blue}{-5} \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ \end{bmatrix} $$ are in row echelon form and $$ \begin{bmatrix} 0 & \color{blue}{-4} & 2 & 3 \\ \color{blue}{5} & 2 & 21 & 4 \\ 0 & 0 & 0 & 0 \\ \end{bmatrix},\ \begin{bmatrix} \color{blue}{5} & 2 & 21 & 4 \\ 0 & 0 & 0 & 0 \\ 0 & \color{blue}{-4} & 2 & 3 \\ \end{bmatrix} \text{ and } \begin{bmatrix} 0 & \color{blue}{300} & 3 & 3 \\ 0 & \color{blue}{300} & 3 & 3 \\ 0 & \color{blue}{300} & 3 & 3 \\ 0 & 0 & 0 & \color{blue}{-5} \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ \end{bmatrix} $$ are not in row echelon form. These matrices still have a rank, but we still have some row operations to do to get them into row echelon form.
In regards to the other parts:
So the specified ranks are correct if the $X$s represent a "wildcard" that can only take on non-zero values. If the $X$s may be zero, the rank could be less than $2$.
Upper triangular and lower triangular matrices refer to square matrices. But we can still have upper triangular matrices that are not in row echelon form, e.g.: \begin{bmatrix} 0 & 0 & \color{blue} 1 \\ 0 & \color{blue} 1 & 1 \\ 0 & 0 & 0 \\ \end{bmatrix} so this is not the right condition anyway. (Although, if a matrix is in row echelon form, we must have $0$s below the main diagonal.)