<?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>2103100 - Disclosure - Stock-based Compensation</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>D2013Q2YTD</ContextID><EntitySchema>http://www.sec.gov/CIK</EntitySchema><EntityValue>0001366367</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_DisclosureOfCompensationRelatedCostsSharebasedPaymentsAbstract</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>Disclosure of Compensation Related Costs, Share-based Payments [Abstract]</Label></Row><Row FlagID="0"><Id>2</Id><IsAbstractGroupTitle>false</IsAbstractGroupTitle><LabelSeparator>

</LabelSeparator><Level>2</Level><ElementName>us-gaap_DisclosureOfCompensationRelatedCostsShareBasedPaymentsTextBlock</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><PreferredLabelRole>verboseLabel</PreferredLabelRole><FootnoteIndexer /><Cells><Cell FlagID="0" ContextID="D2013Q2YTD" UnitID=""><Id>1</Id><IsNumeric>false</IsNumeric><IsRatio>false</IsRatio><DisplayZeroAsNone>false</DisplayZeroAsNone><NumericAmount>0</NumericAmount><RoundedNumericAmount>0</RoundedNumericAmount><NonNumbericText>&lt;div style="font-family:Times New Roman;font-size:10pt;"&gt;&lt;div style="line-height:120%;text-align:justify;font-size:10pt;"&gt;&lt;font style="font-family:inherit;font-size:10pt;font-style:italic;font-weight:bold;"&gt;Stock-based Compensation&lt;/font&gt;&lt;/div&gt;&lt;div style="line-height:120%;text-align:justify;font-size:10pt;"&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;&lt;br clear="none"/&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="line-height:120%;text-align:justify;font-size:10pt;"&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;During the three and six months ended &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;June&amp;#160;30, 2013&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;, &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;534&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;  and &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;1,802&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; options were vested, respectively.  During the three and six months ended &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;June&amp;#160;30, 2012&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;, &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;800&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; and &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;2,500&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; options were vested, respectively.  Total options outstanding at &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;June&amp;#160;30, 2013&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; were &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;53,616&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;, of which &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;4,366&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; options were unvested.&lt;/font&gt;&lt;/div&gt;&lt;div style="line-height:120%;text-align:justify;font-size:10pt;"&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;&lt;br clear="none"/&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="line-height:120%;text-align:justify;font-size:10pt;"&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;During the six months ended June 30, 2013, &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;1,666&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; options were granted.  The weighted average fair value of the options granted was $&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;7.55&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; and was estimated on the date of grant using the Black-Scholes option pricing model with the following assumptions:  dividend yield of &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;0.00%&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;; expected volatility of &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;101.70%&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;:  risk-free interest rate of &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;1.00%&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;; and expected life of &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;7 years&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;.  There were &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;no&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; options exercised for the three and six months ended June 30, 2013.  There were &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;no&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; options granted or exercised for the three and six months ended June 30, 2012.&lt;/font&gt;&lt;/div&gt;&lt;div style="line-height:120%;text-align:justify;font-size:10pt;"&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;&lt;br clear="none"/&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="line-height:120%;text-align:justify;font-size:10pt;"&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;As of &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;June&amp;#160;30, 2013&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;, there are &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;211,159&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; restricted shares outstanding, of which &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;32,878&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; shares of restricted stock are vested and &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;178,281&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; shares are nonvested.    As of December 31, 2012, there were &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;207,917&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;  restricted shares outstanding, of which &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;14,549&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; shares of restricted stock were vested and &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;193,368&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; shares are nonvested.  There were &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;3,242&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; shares of restricted stock issued during the three and six months ended June 30, 2013 at an average fair value of $&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;12.65&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;.  There were &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;165,827&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; shares of restricted stock issued during the three and six months ended June 30, 2012 at an average fair value of $&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;6.93&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;, and &lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;color:#000000;text-decoration:none;"&gt;6,667&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; restricted shares were forfeited.&lt;/font&gt;&lt;/div&gt;&lt;div style="line-height:120%;text-align:justify;font-size:10pt;"&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;&lt;br clear="none"/&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="line-height:120%;text-align:justify;font-size:10pt;"&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;The compensation expense related to options and restricted shares was &lt;/font&gt;&lt;font style="font-family:Times New Roman;font-size:10pt;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;"&gt;$124,040&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; and $&lt;/font&gt;&lt;font style="font-family:Times New Roman;font-size:10pt;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;"&gt;252,530&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; for the three and six month period ended &lt;/font&gt;&lt;font style="font-family:Times New Roman;font-size:10pt;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;"&gt;June&amp;#160;30, 2013&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;, respectively .   The compensation expense related to options and restricted shares was &lt;/font&gt;&lt;font style="font-family:Times New Roman;font-size:10pt;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;"&gt;$129,281&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; and $&lt;/font&gt;&lt;font style="font-family:Times New Roman;font-size:10pt;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;"&gt;164,040&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; for the three and six month period ended &lt;/font&gt;&lt;font style="font-family:Times New Roman;font-size:10pt;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;"&gt;June&amp;#160;30, 2012&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;, respectively.  As of &lt;/font&gt;&lt;font style="font-family:Times New Roman;font-size:10pt;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;"&gt;June&amp;#160;30, 2013&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; and December 31, 2012, there was &lt;/font&gt;&lt;font style="font-family:Times New Roman;font-size:10pt;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;"&gt;$794,497&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; and $&lt;/font&gt;&lt;font style="font-family:Times New Roman;font-size:10pt;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;"&gt;993,423&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;, respectively, of total unrecognized compensation cost related to nonvested share-based compensation arrangements granted under all of the Company's stock benefit plans.  This cost is expected to be recognized over an average vesting period of &lt;/font&gt;&lt;font style="font-family:Times New Roman;font-size:10pt;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;"&gt;1.8&lt;/font&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt; years.  &lt;/font&gt;&lt;/div&gt;&lt;div style="line-height:120%;text-align:justify;font-size:10pt;"&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;&lt;br clear="none"/&gt;&lt;/font&gt;&lt;/div&gt;&lt;div style="line-height:120%;text-align:justify;font-size:10pt;"&gt;&lt;font style="font-family:inherit;font-size:10pt;"&gt;Effective May 28, 2013, the Company executed a one-for-three reverse stock split.   All outstanding options and restricted shares  and earnings per share calculations have been adjusted for the effect of this reverse stock split.  For additional information related to the reverse stock split, see Note 16, Other Events.&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 compensation-related costs for equity-based compensation, which may include disclosure of policies, compensation plan details, allocation of equity compensation, incentive distributions, equity-based arrangements to obtain goods and services, deferred compensation arrangements, employee stock ownership plan details and employee stock purchase plan details.</ElementDefenition><ElementReferences>Reference 1: http://www.xbrl.org/2003/role/presentationRef

 -Publisher FASB

 -Name Accounting Standards Codification

 -Topic 718

 -SubTopic 10

 -Section 50

 -Paragraph 1

 -URI http://asc.fasb.org/extlink&amp;oid=6415400&amp;loc=d3e5047-113901



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

 -Publisher FASB

 -Name Accounting Standards Codification

 -Topic 718

 -SubTopic 10

 -Section 50

 -Paragraph 2

 -URI http://asc.fasb.org/extlink&amp;oid=6415400&amp;loc=d3e5070-113901



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

 -Publisher FASB

 -Name Accounting Standards Codification

 -Topic 505

 -SubTopic 50

 -Section 50

 -Paragraph 1

 -URI http://asc.fasb.org/extlink&amp;oid=6406099&amp;loc=d3e25284-112666



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

 -Publisher FASB

 -Name Statement of Financial Accounting Standard (FAS)

 -Number 123R

 -Paragraph 64, 65, A240

 -LegacyDoc This reference is SUPERSEDED by the Accounting Standards Codification effective for interim and annual periods ending after September 15, 2009.  This reference is included to help users transition from the previous accounting hierarchy and will be removed from future versions of this taxonomy.



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

 -Publisher FASB

 -Name Accounting Standards Codification

 -Topic 718

 -SubTopic 40

 -Section 50

 -Paragraph 1

 -URI http://asc.fasb.org/extlink&amp;oid=6418621&amp;loc=d3e17540-113929



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

 -Publisher FASB

 -Name Accounting Standards Codification

 -Topic 718

 -SubTopic 10

 -Section 50

 -Paragraph 4

 -URI http://asc.fasb.org/extlink&amp;oid=6415400&amp;loc=d3e5444-113901



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

 -Publisher SEC

 -Name Staff Accounting Bulletin (SAB)

 -Number Topic 14



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

 -Publisher AICPA

 -Name Statement of Position (SOP)

 -Number 93-6

 -Paragraph 53

 -LegacyDoc This reference is SUPERSEDED by the Accounting Standards Codification effective for interim and annual periods ending after September 15, 2009.  This reference is included to help users transition from the previous accounting hierarchy and will be removed from future versions of this taxonomy.



</ElementReferences><IsTotalLabel>false</IsTotalLabel><UnitID>0</UnitID><Label>Stock-based Compensation</Label></Row></Rows><Footnotes /><IsEquityReport>false</IsEquityReport><ReportName>Stock-based Compensation</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://www.yadkinvalleybank.com/role/StockBasedCompensation</RoleURI><NumberOfCols>1</NumberOfCols><NumberOfRows>2</NumberOfRows></InstanceReport>
