The paper presents the shape and discrete sizing optimization of timber trusses with the consideration of joint flexibility. The optimization was performed by the Mixed-Integer Non-linear Programming (MINLP) approach. In the optimization model an economic objective function for minimizing the structure's self-manufacturing costs was defined. The design conditions in accordance with Eurocode 5 were considered as optimization constraints. The internal forces and deflections were calculated by finite element analysis. The structural stiffness matrix was composed by considering fictiously decreased cross-sectional areas of all the flexibly connected elements. The cross-section dimensions and the number of fasteners were defined as discrete sizing variables, while the joint coordinates were considered as shape variables. The applicability of the proposed approach is demonstrated through some numerical examples, presented at the end of the paper.