The rule in plain English
Texas counts from the day the tenant surrenders the premises. On or before the 30th day after it, the landlord refunds the deposit. Anything kept back for damages or charges the tenant owes under the lease goes on a written description and itemized list sent with the balance (Tex. Prop. Code §§ 92.103, 92.104).
Two things change the count in practice. The duty to refund waits for the tenant's written forwarding address (§ 92.107). And mailing counts by the postmark (§ 92.1041).
For a tenant who is behind on rent, the Texas notice is available here.
Prepare the Texas noticeMore for Texas landlords: Texas Eviction Notice Selector · Eviction Notice Deadline Calculator · See the Texas documents