<?xml version="1.0" encoding="us-ascii"?><InstanceReport xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Version>2.4.0.8</Version><ReportLongName>0013 - Disclosure - Long term debt</ReportLongName><DisplayLabelColumn>true</DisplayLabelColumn><ShowElementNames>false</ShowElementNames><RoundingOption /><HasEmbeddedReports>false</HasEmbeddedReports><Columns><Column FlagID="0"><Id>1</Id><IsAbstractGroupTitle>false</IsAbstractGroupTitle><LabelSeparator>

</LabelSeparator><CurrencyCode /><FootnoteIndexer /><hasSegments>false</hasSegments><hasScenarios>false</hasScenarios><MCU><KeyName /><CurrencySymbol /><contextRef><ContextID>From2013-01-01to2013-06-30</ContextID><EntitySchema>http://www.sec.gov/CIK</EntitySchema><EntityValue>0001373485</EntityValue><PeriodDisplayName /><PeriodType>duration</PeriodType><PeriodStartDate>2013-01-01T00:00:00</PeriodStartDate><PeriodEndDate>2013-06-30T00:00:00</PeriodEndDate><Segments /><Scenarios /></contextRef><UPS /><CurrencyCode /><OriginalCurrencyCode /></MCU><CurrencySymbol /><Labels><Label Key="CalendarSupplement" Id="0" Label="6 Months Ended" /><Label Key="Calendar" Id="1" Label="Jun. 30, 2013" /></Labels></Column></Columns><Rows><Row FlagID="0"><Id>1</Id><IsAbstractGroupTitle>true</IsAbstractGroupTitle><LabelSeparator>

</LabelSeparator><Level>1</Level><ElementName>us-gaap_LongTermDebtAbstract</ElementName><ElementPrefix>us-gaap_</ElementPrefix><IsBaseElement>true</IsBaseElement><BalanceType>na</BalanceType><PeriodType>duration</PeriodType><IsReportTitle>false</IsReportTitle><IsSegmentTitle>false</IsSegmentTitle><IsCalendarTitle>false</IsCalendarTitle><IsEquityPrevioslyReportedAsRow>false</IsEquityPrevioslyReportedAsRow><IsEquityAdjustmentRow>false</IsEquityAdjustmentRow><IsBeginningBalance>false</IsBeginningBalance><IsEndingBalance>false</IsEndingBalance><IsReverseSign>false</IsReverseSign><FootnoteIndexer /><Cells><Cell FlagID="0" ContextID="" UnitID=""><Id>1</Id><IsNumeric>false</IsNumeric><IsRatio>false</IsRatio><DisplayZeroAsNone>false</DisplayZeroAsNone><NumericAmount>0</NumericAmount><RoundedNumericAmount>0</RoundedNumericAmount><NonNumbericText /><FootnoteIndexer /><CurrencyCode /><CurrencySymbol /><IsIndependantCurrency>false</IsIndependantCurrency><ShowCurrencySymbol>false</ShowCurrencySymbol><DisplayDateInUSFormat>false</DisplayDateInUSFormat></Cell></Cells><ElementDataType>xbrli:stringItemType</ElementDataType><SimpleDataType>string</SimpleDataType><IsTotalLabel>false</IsTotalLabel><UnitID>0</UnitID><Label>Long-term Debt, Unclassified [Abstract]</Label></Row><Row FlagID="0"><Id>2</Id><IsAbstractGroupTitle>false</IsAbstractGroupTitle><LabelSeparator>

</LabelSeparator><Level>2</Level><ElementName>us-gaap_LongTermDebtTextBlock</ElementName><ElementPrefix>us-gaap_</ElementPrefix><IsBaseElement>true</IsBaseElement><BalanceType>na</BalanceType><PeriodType>duration</PeriodType><IsReportTitle>false</IsReportTitle><IsSegmentTitle>false</IsSegmentTitle><IsCalendarTitle>false</IsCalendarTitle><IsEquityPrevioslyReportedAsRow>false</IsEquityPrevioslyReportedAsRow><IsEquityAdjustmentRow>false</IsEquityAdjustmentRow><IsBeginningBalance>false</IsBeginningBalance><IsEndingBalance>false</IsEndingBalance><IsReverseSign>false</IsReverseSign><FootnoteIndexer /><Cells><Cell FlagID="0" ContextID="From2013-01-01to2013-06-30" UnitID=""><Id>1</Id><IsNumeric>false</IsNumeric><IsRatio>false</IsRatio><DisplayZeroAsNone>false</DisplayZeroAsNone><NumericAmount>0</NumericAmount><RoundedNumericAmount>0</RoundedNumericAmount><NonNumbericText>&lt;div style="text-indent: 0pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: center"&gt;&lt;div style="text-indent: 0pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: bold 10pt Times New Roman"&gt;8 &amp;#8211; Long term debt &lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: bold 10pt Times New Roman"&gt;&lt;a name="FIS_UNIDENTIFIED_TABLE_9"&gt;&lt;/a&gt;Notes Payable Green Shoe Investments &amp;#8211; Related Party&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;&amp;#160;&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;In connection with the January 2011&amp;#160;merger, the Company, as the accounting acquirer, assumed an unsecured loan from Green Shoe Investments Ltd. (&amp;#8220;Green Shoe&amp;#8221;) in the principal amount of $487,000 at an interest rate of 5.0%&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;

&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;On
April 26, 2011, the Company entered into a Loan Agreement with Green Shoe, and the Company executed and delivered a
Promissory Note to Green Shoe in connection therewith.&amp;#160;&amp;#160;The amount of the Promissory Note and the loan from Green
Shoe (the &amp;#8220;Green Shoe Loan&amp;#8221;) was $550,936 and the purpose of the Green Shoe Loan was to consolidate and extend
all of the loans owed by the Company and its predecessors to Green Shoe including without limitation the
following:&amp;#160;&amp;#160;(i) loan dated May 9, 2008 in the principal amount of $100,000, (ii) loan dated May 23, 2008 in the
principal amount of $150,000, (iii) loan dated July 18, 2008 in the principal amount of $50,000, (iv) loan dated February 24,
2009 in the principal amount of $100,000, and (v) loan dated April 29, 2009 in the principal amount of $87,000 plus accrued
interest of $63,936.&amp;#160;&amp;#160;The Green Shoe Loan was unsecured.&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;

&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;Beginning March 31, 2011 (the effective date of the Promissory Note), the amounts owed under the Promissory Note began to accrue interest at a rate of 9.99%, and the Promissory Note provided that no payments of principal or interest were due until the maturity date of September 30, 2012.&amp;#160;&amp;#160;The Company is obligated to pay all accrued interest and make a principal payment equal to one-third of the principal owed upon the closing of an equity offering resulting in a specified amount of net proceeds to the Company.&amp;#160;&amp;#160;In addition, Green Shoe was granted the right to convert the principal and interest owed into shares of common stock of the Company at a conversion price of $4.00 per share. The principal balance of the note as of September 30, 2012 was $367,309.&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;

&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;&lt;a name="V222832_10Q_HTM_PAGE16"&gt;&lt;/a&gt;The debt and associated accrued interest were not repaid at maturity on September 30, 2012.&amp;#160;&amp;#160;On October 22, 2012, the Company received notice from the lender&amp;#8217;s counsel that it would be considered in default on the note beginning November 1, 2012 if the note and accrued interest were not paid in full.&amp;#160;&amp;#160;From November 1, 2012, the note began to accrue interest at the default rate of 18%.&amp;#160;&amp;#160;On November 30, 2012, Jackson Street Investors, LLC purchased the note from Green Shoe Investments.&amp;#160;&amp;#160;Subsequently, on December 12, 2012, Red Mountain Resources, Inc. purchased the note from Jackson Street Investors, LLC.&amp;#160;&amp;#160;As of December 31, 2012, the note had a principal balance of $367,309 and an accrued interest balance of $62,924.&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;

&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;On February 28, 2013, the Company&amp;#8217;s Board of Directors approved a resolution to modify the terms of the note so that the conversion price was reduced from $4.00 to $1.50 per share.&amp;#160;&amp;#160;On February 28, 2013, Red Mountain Resources, Inc. converted the principal balance of $367,309 and accrued interest balance of $73,611 into 293,947 shares of the Company&amp;#8217;s common stock.&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;&amp;#160;&amp;#160;&amp;#160;&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: bold 10pt Times New Roman"&gt;Notes Payable Little Bay Consulting &amp;#8211; Related Party&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;

&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;In connection with the January 2011&amp;#160;merger, the Company, as the accounting acquirer, assumed an unsecured loan from Little Bay Consulting SA (&amp;#8220;Little Bay&amp;#8221;)&amp;#160;in the principal amount of $520,000 at an interest rate of 5%.&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;

&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;On April 26, 2011, the Company entered into a Loan Agreement with Little Bay, and the Company executed and delivered a Promissory Note to Little Bay in connection therewith.&amp;#160;&amp;#160;The amount of the Promissory Note and the loan from Little Bay (the &amp;#8220;Little Bay Loan&amp;#8221;) was $595,423 and the purpose of the Little Bay Loan was to consolidate and extend all of the loans owed by the Company and its predecessors to Little Bay including without limitation the following: (i) loan dated March 7, 2008 in the original principal amount of $220,000, (ii) loan dated July 18, 2008 in the original principal amount of $100,000, and (iii) loan dated October 3, 2008 in the principal amount of $200,000 plus accrued interest of $75,423.&amp;#160;&amp;#160;The Little Bay Loan was unsecured.&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;



&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;Beginning March 31, 2011 (the effective date of the Promissory Note), the amounts owed under the Promissory Note began to accrue interest at a rate of 9.99%, and the Promissory Note provided that no payments of principal or interest were due until the maturity date of September 30, 2012.&amp;#160;&amp;#160;The Company is obligated to pay all accrued interest and make a principal payment equal to one-third of the principal owed upon the closing of an equity offering resulting in a specified amount of net proceeds to the Company.&amp;#160;&amp;#160;In addition, Little Bay was granted the right to convert the principal and interest owed into shares of common stock of the Company at a conversion price of $4.00 per share. The principal balance of the note as of September 30, 2012 is $396,969.&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;

&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;The debt and associated accrued interest were not repaid at maturity on September 30, 2012.&amp;#160;&amp;#160;On October 22, 2012, the Company received notice from the lender&amp;#8217;s counsel that it would be considered in default on the note beginning November 1, 2012 if the note and accrued interest were not paid in full.&amp;#160;&amp;#160;From November 1, 2012, the note began to accrue interest at the default rate of 18%.&amp;#160;&amp;#160;&amp;#160;&amp;#160;On November 30, 2012, Jackson Street Investors, LLC purchased the note from Little Bay Consulting, S.A.&amp;#160;&amp;#160;Subsequently, on December 12, 2012, Red Mountain Resources, Inc. purchased the note from Jackson Street Investors, LLC.&amp;#160;&amp;#160;As of December 31, 2012, the note had a principal balance of $396,969 and an accrued interest balance of $68,005.&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;

&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;On February 28, 2013, the Company&amp;#8217;s Board of Directors approved a resolution to modify the terms of the note so that the conversion price was reduced from $4.00 to $1.50 per share.&amp;#160;&amp;#160;On February 28, 2013, Red Mountain Resources, Inc. converted the principal balance of $396,969 and accrued interest balance of $79,555 into 317,683 shares of the Company&amp;#8217;s common stock.&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;&amp;#160;&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: bold 10pt Times New Roman"&gt;Operating Line of Credit&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;

&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="display: inline; font: 10pt Times New Roman"&gt;As of December 31, 2011, the borrowing base on the Texas Capital Bank (&amp;#8220;TCB&amp;#8221;) line of credit was $4,500,000.&amp;#160;&amp;#160;Effective March 1, 2012, the borrowing base was increased to $9,500,000. The interest rate was calculated at the greater of the adjusted base rate or 4%. The line of credit is collateralized by producing wells was set to mature on January 14, 2014.&amp;#160;&amp;#160;As a result of the sale of certain interests in oil and gas properties, effective August 1, 2012, the borrowing base was reduced by $750,000 and that amount was repaid to TCB out of the sale proceeds.&lt;/font&gt;&lt;/div&gt;

&lt;div style="text-indent: 0pt; display: block"&gt;&lt;br /&gt;
&lt;/div&gt;

&lt;div style="text-indent: 36pt; display: block; margin-left: 0pt; margin-right: 0pt; text-align: left"&gt;&lt;font style="font: 10pt Times New Roman"&gt;On
February 5, 2013, the Company entered into a Senior First Lien Secured Credit Agreement with Red Mountain Resources, Inc., Black
Rock Capital, Inc. and RMR Operating, LLC and Independent Bank, as Lender.&amp;#160;&amp;#160;Red Mountain owns approximately 81% of the
outstanding common stock of Cross Border and Black Rock and RMR Operating are wholly owned subsidiaries of Red Mountain.&amp;#160;&amp;#160;On
February 5, 2013, the Company drew $8,900,000 on the line of credit and used those funds to pay off the line of credit and associated
accrued interest.&amp;#160;&amp;#160;On February 29, 2013, the Company drew $2,000,000 and on May 24, 2013, the Company drew a further
$1,300,000 on the line of credit and used those funds to pay accounts payable related to the drilling program.&amp;#160;&amp;#160;As of
June 30, 2013, the Credit Agreement balance was $12,200,000, leaving $200,000 available.&lt;/font&gt; &lt;/div&gt;

&lt;/div&gt;</NonNumbericText><FootnoteIndexer /><CurrencyCode /><CurrencySymbol /><IsIndependantCurrency>false</IsIndependantCurrency><ShowCurrencySymbol>false</ShowCurrencySymbol><DisplayDateInUSFormat>false</DisplayDateInUSFormat></Cell></Cells><ElementDataType>nonnum:textBlockItemType</ElementDataType><SimpleDataType>na</SimpleDataType><ElementDefenition>The entire disclosure for long-term debt.</ElementDefenition><ElementReferences>Reference 1: http://www.xbrl.org/2003/role/presentationRef

 -Publisher SEC

 -Name Regulation S-X (SX)

 -Number 210

 -Section 02

 -Paragraph 22

 -Article 5



Reference 2: http://www.xbrl.org/2003/role/presentationRef

 -Publisher FASB

 -Name Accounting Standards Codification

 -Topic 210

 -SubTopic 10

 -Section S99

 -Paragraph 1

 -Subparagraph (SX 210.5-02.22)

 -URI http://asc.fasb.org/extlink&amp;oid=6877327&amp;loc=d3e13212-122682



</ElementReferences><IsTotalLabel>false</IsTotalLabel><UnitID>0</UnitID><Label>Long term debt</Label></Row></Rows><Footnotes /><IsEquityReport>false</IsEquityReport><ReportName>Long term debt</ReportName><MonetaryRoundingLevel>UnKnown</MonetaryRoundingLevel><SharesRoundingLevel>UnKnown</SharesRoundingLevel><PerShareRoundingLevel>UnKnown</PerShareRoundingLevel><ExchangeRateRoundingLevel>UnKnown</ExchangeRateRoundingLevel><HasCustomUnits>true</HasCustomUnits><IsEmbedReport>false</IsEmbedReport><IsMultiCurrency>false</IsMultiCurrency><ReportType>Sheet</ReportType><RoleURI>http://xbres.com/role/LongTermDebt</RoleURI><NumberOfCols>1</NumberOfCols><NumberOfRows>2</NumberOfRows></InstanceReport>
