Form design: segmenting fields into brackets

Form design: segmenting fields into brackets

On my input form there are 40 fields.  I need to categorize the fields into 5 to 6 segments.... how do I design this?  Tabs?   How to put a horizontal dividing bar between segments/sections?

thanks gurus.